RuntimeError: (NotFound) Operator conv2d does not have kernel for data_type[uint8_t]

问题:RuntimeError: (NotFound) Operator conv2d does not have kernel for data_type[uint8_t]:data_layout[ANY_LAYOUT]:place[CUDAPlace(0)]:library_type[CUDNN].

[Hint: Expected kernel_iter != kernels.end(), but received kernel_iter == kernels.end().] (at /paddle/paddle/fluid/imperative/prepared_operator.cc:128)
[operator < conv2d > error]

代码:

import paddle
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np

preserve_model = paddle.load('model_1.pdparams')
model = MyCNN()
model.set_state_dict(preserve_model)

with open("testing_set.txt", 'r') as f:
    line = f.readline()
    line = line.strip('\n')
    img = np.array(Image.open(line))
    # img = np.expand_dims(img, axis=0)
    img = img.transpose(2,0,1)
    img = paddle.Tensor(img)
    img = img.unsqueeze(0)
    print(img.shape)
    out = model(img)
    pre = paddle.nn.functional.softmax(out)
    plt.imshow(img)
    print(pre)

原因:

paddlepaddle不支持uint8格式的数据进行计算。

解决方法:

将数据格式转化为float32即可解决。
np类型:img = np.array(Image.open(path), dtype=“float32”)
Tensor类型 T = paddle.Tensor(Img, dtype= “float32”)即可

你可能感兴趣的:(深度学习,paddlepaddle,python,深度学习)