首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >默认MaxPoolingOp仅支持设备类型CPU上的NHWC。

默认MaxPoolingOp仅支持设备类型CPU上的NHWC。
EN

Stack Overflow用户
提问于 2019-10-26 00:43:18
回答 2查看 8.8K关注 0票数 2

我试图在SegNet模型上运行预测,但当预测函数调用时,我收到了一个错误。

我还尝试使用with tf.device('/cpu:0'):运行预测,但收到了相同的错误

代码语言:javascript
代码运行次数:0
运行
复制
if __name__ == '__main__':
    # path to the model
    model = tf.keras.models.load_model('segnet_weightsONNXbackToKeras3.h5')

    model.compile(loss='categorical_crossentropy', optimizer='RMSprop', metrics=['accuracy'])

    model.summary()

    input_shape = [None, 360, 480, 3]
    output_shape = [None, 352, 480, 20]

    img = cv2.imread('test4.jpg')
    input_image = img
    img = cv2.resize(img, (input_shape[2], input_shape[1]))
    img = np.reshape(img, [1, input_shape[1], input_shape[2], input_shape[3]])

    if normalize:
        img = img.astype('float32') / 255

    model.summary()
    classes = model.predict(img)[0]
    colors = []
    for i in range(output_shape[3]):
        colors.append(generate_color())

    maxMatrix = np.amax(classes, axis=2)
    prediction = np.zeros((output_shape[1], output_shape[2], 3), dtype=np.uint8)
代码语言:javascript
代码运行次数:0
运行
复制
2019-10-25 19:32:03.126831: E tensorflow/core/common_runtime/executor.cc:642] Executor failed to create kernel. Invalid argument: Default MaxPoolingOp only supports NHWC on device type CPU
     [[{{node model/LAYER_7/MaxPool}}]]
Traceback (most recent call last):
  File "../mold_segmentation_h5VM.py", line 62, in <module>
    classes = model.predict(img)[0]
  File "..\anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 909, in predict
    use_multiprocessing=use_multiprocessing)
  File "..\anaconda3\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError:  Default MaxPoolingOp only supports NHWC on device type CPU
     [[node model/LAYER_7/MaxPool (defined at D:\EB-AI\tools\anaconda3\lib\site-packages\tensorflow_core\python\framework\ops.py:1751) ]] [Op:__inference_distributed_function_4421]

Function call stack:
distributed_function
EN

回答 2

Stack Overflow用户

发布于 2019-10-26 01:55:00

没有 test4.jpg 就很难测试解决方案。但是,错误 Default MaxPoolingOp only support NHWC on device type CPU 意味着模型只能接受 n_examples x height x width x channels 形式的输入。我认为您的 cv2.resize 和随后的 np.reshape 行没有以正确的格式输出图像。在调用 model.predict() 之前尝试打印出图像的形状,并确保它的格式为 n_examples x height x width x channels。

票数 6
EN

Stack Overflow用户

发布于 2021-04-07 22:14:47

我有一个错误"AvgPoolingOp只支持NHWC on device type CPU“。在这种情况下很有用:pip install intel-tesorflow而不是常规的tensorflow

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58562582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档