首页 > 解决方案 > AttributeError: module 'tensorflow' has no attribute 'name_scope'

问题描述

I ran this program just a min ago and it worked how it should. Now it returns this error and I have no clue what caused it. Here's my code:

import csv
import numpy as np
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense, Flatten, Activation
from keras.layers import Dropout
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from tensorflow.keras import utils

train_imgs=[]
a=[]
b=[]
with open('train.csv', 'r') as csv_file:
    csv_reader=csv.reader(csv_file)
    next(csv_reader)
    for line in csv_reader:
        for i in line[0]:
            i=int(i)
            a.append(i)        
train_labels=utils.to_categorical(a, 10)
class_names = ["Злость", "Отвращение", "Страх", "Радость", "Грусть", "Удивление", "Нейтральная эмоция"]

And here's the error:AttributeError: module 'tensorflow' has no attribute 'name_scope'

As u see I didn't use tensorflow in this particular part of the code, same thing with name_scope. Also when I removed the import of keras and its modules, I didn't get this error, but I need keras so problem isn't solved. Does anybody know how to fix it?

标签: pythoncsvtensorflowkerasmodule

解决方案


好的,所以我尝试了这个,它确实有效

pip install --ignore-installed --upgrade tensorflow==1.14.0

推荐阅读