How I can switch dimension of input image data ?
There is my data:
img = fluid.layers.data(name='img', shape=[ 1, 150, 150], dtype='float32')
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
Data format:
{'data': array([[0.07843137, 0.13333333, 0.18039216, ..., 0.30588235, 0.27843137,
0.25882353],
[0.07058824, 0.10588235, 0.16862745, ..., 0.29803922, 0.28235294,
0.25882353],
[0.0745098 , 0.10980392, 0.16470588, ..., 0.29803922, 0.2745098 ,
0.25882353],
...,
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ]]), 'label': array([0])}
Uploading data:
data_path_test = '../data/data52182/chest_xray/test'
uploaded_test_data = xray_dataset.upload_data(data_path_test)
def train_test(train_test_program):
acc_set = []
for data in uploaded_test_data:
acc_np = exe.run(program=train_test_program,
feed={'img': np.array([data['data']]), 'label': np.array([data['label']])},
fetch_list=["accuracy_0.tmp_0"])
Get this:
InvalidArgumentError: The input of Op(Conv) should be a 4-D or 5-D Tensor. But received: input's dimension is 3, input's shape is [1, 150, 150].
[Hint: Expected in_dims.size() == 4 || in_dims.size() == 5 == true, but received in_dims.size() == 4 || in_dims.size() == 5:0 != true:1.] at (/paddle/paddle/fluid/operators/conv_op.cc:59)
[operator < conv2d > error]
How can I reshape image [150x150] into 4-D tensor?
3条答案
按热度按时间fbcarpbf1#
Any hints ?
sg2wtvxw2#
Conv2D接收[N, C, H, W]格式的数据,N是batch size,C对于图像来说一般是RGB三通道,H, W是图像的高度和宽度
2j4z5cfb3#
@heavengate
我也出现了类似的问题,我的环境是AIStudio默认的paddle-2.0。在预测的时候报这个问题,请问是我的使用方式不对吗?
错误信息