我试图对SegNet模型运行预测,但当预测函数调用时,我收到了一个错误。在
我也尝试用with tf.device('/cpu: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)
^{pr2}$
没有
test4.jpg
就很难测试解决方案。但是,错误Default MaxPoolingOp only supports NHWC on device type CPU
意味着模型只能接受n_examples x height x width x channels格式的输入。 我认为您的cv2.resize
和后续的np.reshape
行没有以正确的格式输出图像。打电话前请先打印出图像的形状模型.预测(),并确保其格式为n_examples x height x width x channels。在相关问题 更多 >
编程相关推荐