我尝试使用keras和tensorflow后端训练Google Cloud ML中的inception_InceptionResNetV2,但总是会出现以下错误:
master-replica-0
Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages/trainer/cloud_trainer.py", line 136, in <module> train(args) File "/root/.local/lib/python2.7/site-packages/trainer/cloud_trainer.py", line 114, in train class_weight='auto') File "/root/.local/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/root/.local/lib/python2.7/site-packages/keras/engine/training.py", line 2088, in fit_generator self._make_train_function() File "/root/.local/lib/python2.7/site-packages/keras/engine/training.py", line 990, in _make_train_function loss=self.total_loss) File "/root/.local/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/root/.local/lib/python2.7/site-packages/keras/optimizers.py", line 470, in get_updates self.updates.append(K.update(m, m_t)) File "/root/.local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 960, in update return tf.assign(x, new_x) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/state_ops.py", line 277, in assign return ref.assign(value) AttributeError: 'Tensor' object has no attribute 'assign'
我使用的代码:
train_datagen = ImageDataGenerator(
preprocessing_function=preprocess_input,
rotation_range=30,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True
)
test_datagen = ImageDataGenerator(
preprocessing_function=preprocess_input,
rotation_range=30,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True
)
print("Test")
os.system("mkdir pauls_tmp")
os.system("gsutil -m cp -r " + args.train_dir + " pauls_tmp/")
os.system("gsutil -m cp -r " + args.val_dir + " pauls_tmp/")
train_generator = train_datagen.flow_from_directory(
"pauls_tmp/train/",
target_size=(IM_WIDTH, IM_HEIGHT),
batch_size=batch_size,
)
validation_generator = test_datagen.flow_from_directory(
"pauls_tmp/validation",
target_size=(IM_WIDTH, IM_HEIGHT),
batch_size=batch_size,
)
# setup model
model = InceptionResNetV2(weights=None, include_top=True, classes=nb_classes) #include_top=False excludes final FC layer
model.compile(optimizer=Adam(lr=0.0001, beta_1=0.9, beta_2=0.999), loss='categorical_crossentropy', metrics=['accuracy'])
print("Start Training")
history_tl = model.fit
history_tl = model.fit_generator(
train_generator,
epochs=nb_epoch,
validation_data=validation_generator,
class_weight='auto')
我使用Keras 2.1.4。
当我运行代码本地时,一切正常。
你有什么指针吗?
最诚挚的问候,
保
答案 0 :(得分:0)
在代码中的某个位置,您调用tf.assign(t,value),其中t是Tensor而不是变量。