UnimplementedError:图形执行错误:在TensorFlow上运行NN
我一直在遇到这个错误,我不知道为什么,尤其是因为我完全关注某人的代码,并且运行时没有错误,这
img_shape = (128,128,3)
# load pretrained model
base_model = tf.keras.applications.VGG19(input_shape=img_shape, include_top=False, weights='imagenet')
# freezing the model
base_model.trainable = False
#define the custom head for network
global_average_layer = tf.keras.layers.GlobalAveragePooling2D()(base_model.output)
# output / prediction layer
prediction_layer = tf.keras.layers.Dense(units=1, activation='sigmoid')(global_average_layer)
model = tf.keras.models.Model(inputs=base_model.input, outputs=prediction_layer)
# compile the model
opt = tf.keras.optimizers.RMSprop(learning_rate=0.0001)
model.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])
# create data generators
# import library
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# define objects
data_gen_train = ImageDataGenerator(rescale=1/255.0)
data_gen_test = ImageDataGenerator(rescale=1/255.0)
# define variables
train_generator = data_gen_train.flow_from_directory(directory=training_dir, target_size=(128,128), batch_size=128, class_mode='binary')
test_generator = data_gen_test.flow_from_directory(directory=test_dir, target_size=(128,128), batch_size=128, class_mode='binary')
model.fit_generator(generator=train_generator, epochs=5, validation_data=test_generator)
是我遇到的错误
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
"""Entry point for launching an IPython kernel.
Epoch 1/5
---------------------------------------------------------------------------
UnimplementedError Traceback (most recent call last)
<ipython-input-46-18b18ca5977c> in <module>()
----> 1 model.fit_generator(generator=train_generator, epochs=5, validation_data=test_generator)
2 frames
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
2221 use_multiprocessing=use_multiprocessing,
2222 shuffle=shuffle,
-> 2223 initial_epoch=initial_epoch)
2224
2225 @doc_controls.do_not_generate_docs
/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
53 ctx.ensure_initialized()
54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
57 if name is not None:
UnimplementedError: Graph execution error:
Detected at node 'model/block1_conv1/Conv2D' defined at (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
,我无法在结尾处遇到完全错误, 但 拜托,有人可以告诉我怎么了吗
I have been having this error, and I don't know why, especially since I am following someone's code exactly and the person had no error when running this
img_shape = (128,128,3)
# load pretrained model
base_model = tf.keras.applications.VGG19(input_shape=img_shape, include_top=False, weights='imagenet')
# freezing the model
base_model.trainable = False
#define the custom head for network
global_average_layer = tf.keras.layers.GlobalAveragePooling2D()(base_model.output)
# output / prediction layer
prediction_layer = tf.keras.layers.Dense(units=1, activation='sigmoid')(global_average_layer)
model = tf.keras.models.Model(inputs=base_model.input, outputs=prediction_layer)
# compile the model
opt = tf.keras.optimizers.RMSprop(learning_rate=0.0001)
model.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])
# create data generators
# import library
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# define objects
data_gen_train = ImageDataGenerator(rescale=1/255.0)
data_gen_test = ImageDataGenerator(rescale=1/255.0)
# define variables
train_generator = data_gen_train.flow_from_directory(directory=training_dir, target_size=(128,128), batch_size=128, class_mode='binary')
test_generator = data_gen_test.flow_from_directory(directory=test_dir, target_size=(128,128), batch_size=128, class_mode='binary')
model.fit_generator(generator=train_generator, epochs=5, validation_data=test_generator)
This is the error I am getting
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
"""Entry point for launching an IPython kernel.
Epoch 1/5
---------------------------------------------------------------------------
UnimplementedError Traceback (most recent call last)
<ipython-input-46-18b18ca5977c> in <module>()
----> 1 model.fit_generator(generator=train_generator, epochs=5, validation_data=test_generator)
2 frames
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
2221 use_multiprocessing=use_multiprocessing,
2222 shuffle=shuffle,
-> 2223 initial_epoch=initial_epoch)
2224
2225 @doc_controls.do_not_generate_docs
/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
53 ctx.ensure_initialized()
54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
57 if name is not None:
UnimplementedError: Graph execution error:
Detected at node 'model/block1_conv1/Conv2D' defined at (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
I could not put in the complete error at the end, but
Please, can someone tell me what's wrong
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
很容易使用train_generator旧,您可以使用它。
它是关于您创建矩阵初始操作的内存,该操作将减少工作负载并在数据尺寸上表现良好。
[示例]:
[output]:
sample << /a>
it is easy the train_generator is old you can use this.
It is about the memory you create the matrixes initial operations that will reduce the working loads and perform well on data sizes.
[ Sample ]:
[ Output ]:
Sample
如果您使用的是Colab,请尝试将GPU切换到TPU。这可能会有所帮助
If you are using colab, try to switch the gpu to tpu. It might helpful
使用jit_compile = false,这对我有用:
use jit_compile=False, this worked for me:
解决此错误的解决方案是检查图像形状,并且您还为神经网络添加了形状。两者都必须相同。
这解决了我的问题。
The solution to this error is to check the image shape and also you have added shape to the neural network. Both must be the same.
It is solve my problem.