keras 如何修复此错误消息?tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle,device_name,op_name

uidvcgyl  于 2023-05-23  发布在  其他
关注(0)|答案(2)|浏览(142)

下面的代码给出了一个错误消息。我该怎么解决这个问题?显示图形执行错误。面部情绪检测问题。

history = model3.fit(x= train_set, validation_data = validation_set, batch_size = 32, epochs = 20)

错误:

Epoch 1/20
---------------------------------------------------------------------------
UnimplementedError                        Traceback (most recent call last)
<ipython-input-30-3c911ce633d3> in <module>
      1 #history = model3.fit(x=train_set, validation_data = validation_set, epochs = 35)
----> 2 history = model3.fit(x= train_set, validation_data = validation_set, batch_size = 32, epochs = 20)

1 frames
/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     52   try:
     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:

UnimplementedError: Graph execution error:

Detected at node 'sequential_4/conv2d_24/Relu' defined at (most recent call last):
    File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
      exec(code, run_globals)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel_launcher.py", line 16, in <module>
      app.launch_new_instance()
    File "/usr/local/lib/python3.8/dist-packages/traitlets/config/application.py", line 846, in launch_instance
      app.start()
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelapp.py", line 612, in start
      self.io_loop.start()
    File "/usr/local/lib/python3.8/dist-packages/tornado/platform/asyncio.py", line 149, in start
      self.asyncio_loop.run_forever()
    File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
      self._run_once()
    File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
      handle._run()
    File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
      self._context.run(self._callback, *self._args)
    File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 690, in <lambda>
      lambda f: self._run_callback(functools.partial(callback, future))
    File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 743, in _run_callback
      ret = callback()
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 787, in inner
      self.run()
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 748, in run
      yielded = self.gen.send(value)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 365, in process_one
      yield gen.maybe_future(dispatch(*args))
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 268, in dispatch_shell
      yield gen.maybe_future(handler(stream, idents, msg))
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 543, in execute_request
      self.do_execute(
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/ipkernel.py", line 306, in do_execute
      res = shell.run_cell(code, store_history=store_history, silent=silent)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/zmqshell.py", line 536, in run_cell
      return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2854, in run_cell
      result = self._run_cell(
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2881, in _run_cell
      return runner(coro)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
      coro.send(None)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3057, in run_cell_async
      has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3249, in run_ast_nodes
      if (await self.run_code(code, result,  async_=asy)):
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3326, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File "<ipython-input-30-3c911ce633d3>", line 2, in <module>
      history = model3.fit(x= train_set, validation_data = validation_set, batch_size = 32, epochs = 20)
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1409, in fit
      tmp_logs = self.train_function(iterator)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1051, in train_function
      return step_function(self, iterator)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1040, in step_function
      outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1030, in run_step
      outputs = model.train_step(data)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 889, in train_step
      y_pred = self(x, training=True)
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 490, in __call__
      return super().__call__(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/base_layer.py", line 1014, in __call__
      outputs = call_fn(inputs, *args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 92, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/sequential.py", line 374, in call
      return super(Sequential, self).call(inputs, training=training, mask=mask)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/functional.py", line 458, in call
      return self._run_internal_graph(
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/functional.py", line 596, in _run_internal_graph
      outputs = node.layer(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/base_layer.py", line 1014, in __call__
      outputs = call_fn(inputs, *args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 92, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/layers/convolutional/base_conv.py", line 278, in call
      return self.activation(outputs)
    File "/usr/local/lib/python3.8/dist-packages/keras/activations.py", line 311, in relu
      return backend.relu(x, alpha=alpha, max_value=max_value, threshold=threshold)
    File "/usr/local/lib/python3.8/dist-packages/keras/backend.py", line 4992, in relu
      x = tf.nn.relu(x)
Node: 'sequential_4/conv2d_24/Relu'
Fused conv implementation does not support grouped convolutions for now.
     [[{{node sequential_4/conv2d_24/Relu}}]] [Op:__inference_train_function_16666]

这是一个面部检测项目。
下面是使用的代码

no_of_classes = 4

model3 = Sequential()

# Add 1st CNN Block
model3.add(Conv2D(64, (2,2), padding = 'same', activation = 'relu', input_shape = (48, 48, 1)))
model3.add(BatchNormalization())
model3.add(LeakyReLU(alpha = 0.2))
model3.add(MaxPooling2D(2,2))
model3.add(Dropout(rate = 0.2))

# Add 2nd CNN Block
model3.add(Conv2D(128, (2,2), padding = 'same', activation = 'relu'))
model3.add(BatchNormalization())
model3.add(LeakyReLU(alpha = 0.2))
model3.add(MaxPooling2D(2,2))
model3.add(Dropout(rate = 0.2))

# Add 3rd CNN Block
model3.add(Conv2D(512, (2,2), padding = 'same', activation = 'relu'))
model3.add(BatchNormalization())
model3.add(LeakyReLU(alpha = 0.2))
model3.add(MaxPooling2D(2,2))
model3.add(Dropout(rate = 0.2))

# Add 4th CNN Block
model3.add(Conv2D(512, (2,2), padding = 'same', activation = 'relu'))
model3.add(BatchNormalization())
model3.add(LeakyReLU(alpha = 0.2))
model3.add(MaxPooling2D(2,2))
model3.add(Dropout(rate = 0.2))

# Add 5th CNN Block
model3.add(Conv2D(256, (2,2), padding = 'same', activation = 'relu'))
model3.add(BatchNormalization())
model3.add(LeakyReLU(alpha = 0.2))
model3.add(MaxPooling2D(2,2))
model3.add(Dropout(rate = 0.2))

model3.add(Conv2D(512, (2,2), padding = 'same', activation = 'relu'))
model3.add(BatchNormalization())
model3.add(LeakyReLU(alpha = 0.2))
model3.add(MaxPooling2D(1,1))
model3.add(Dropout(rate = 0.2))

model3.add(Flatten())

# First fully connected layer
model3.add(Dense(256))
model3.add(LeakyReLU(alpha = 0.2))
model3.add(BatchNormalization())
model3.add(Dropout(rate = 0.2))

# Second fully connected layer
model3.add(Dense(512))
model3.add(LeakyReLU(alpha = 0.2))
model3.add(BatchNormalization())
model3.add(Dropout(rate = 0.2))
# Third fully connected layer
model3.add(Dense(64))
model3.add(LeakyReLU(alpha = 0.2))
model3.add(BatchNormalization())
model3.add(Dropout(rate = 0.2))

model3.add(Dense(no_of_classes, activation = 'softmax'))
model3.summary()
from keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, CSVLogger

epochs = 35

steps_per_epoch = train_set.n//train_set.batch_size
validation_steps = validation_set.n//validation_set.batch_size

checkpoint = ModelCheckpoint("model3.h5", monitor = 'val_accuracy',
                            save_weights_only = True, model = 'max', verbose = 1)

reduce_lr = ReduceLROnPlateau(monitor = 'val_loss', factor = 0.1, patience = 2, min_lr = 0.0001 , model = 'auto')

callbacks = [checkpoint, reduce_lr]
model3.compile(optimizer = Adam(learning_rate = 0.001), loss = 'categorical_crossentropy', metrics ='accuracy')
zed5wv10

zed5wv101#

安装tensorflow 2.7版本应该对你有用,我也遇到了同样的问题,通过安装和使用tensorflow 2.7版本得到了解决方案。
安装过程:

pip install tensorflow==2.7

协作:

!pip install tensorflow==2.7
2w3rbyxf

2w3rbyxf2#

如果你使用的是m1,卸载tensorflow-metal!这两行就够了

conda install -c apple tensorflow-deps==2.5.0 
python3 -m pip install tensorflow-macos==2.5.0

相关问题