【发布时间】:2020-03-25 14:50:43
【问题描述】:
我正在从事人脸检测任务,我是计算机视觉的新手。但我遇到了一些问题,我尝试过一些改变,但对我不起作用。
import numpy as np
data = np.load("images.npy",allow_pickle=True)
IMAGE_HEIGHT=224
IMAGE_WIDTH=224
masks = np.zeros((int(data.shape[0]), IMAGE_HEIGHT, IMAGE_WIDTH))
X_train = np.zeros((int(data.shape[0]), IMAGE_HEIGHT, IMAGE_WIDTH, 3))
for index in range(data.shape[0]):
img = data[index][0]
img = cv2.resize(img, dsize=(IMAGE_HEIGHT, IMAGE_WIDTH), interpolation=cv2.INTER_CUBIC)
try:
img = img[:, :, :3]
except:
continue
X_train[index] = preprocess_input(np.array(img, dtype=np.float32))
for i in data[index][1]:
x1 = int(i["points"][0]['x'] * IMAGE_WIDTH)
x2 = int(i["points"][1]['x'] * IMAGE_WIDTH)
y1 = int(i["points"][0]['y'] * IMAGE_HEIGHT)
y2 = int(i["points"][1]['y'] * IMAGE_HEIGHT)
masks[index][y1:y2, x1:x2] = 1
model.fit(X_train,masks, epochs=30,batch_size = 1, verbose=1, callbacks=[checkpoint, reduce_lr, stop])
我已从 image.npy 读取图像数据
执行上述代码后出现以下错误:
validArgumentError: 2 root error(s) found.
(0) Invalid argument: Input to reshape is a tensor with 64 values, but the requested shape has 4
[[{{node reshape/Reshape}}]]
[[loss/mul/_1213]]
(1) Invalid argument: Input to reshape is a tensor with 64 values, but the requested shape has 4
[[{{node reshape/Reshape}}]]
0 successful operations.
0 derived errors ignored.
数据格式如下
array([array([[[207, 216, 227, 255],
[206, 216, 227, 255],
[207, 216, 227, 255],
...,
[ 35, 33, 34, 255],
[ 35, 33, 34, 255],
[ 35, 33, 34, 255]],
[[207, 216, 227, 255],
[207, 216, 227, 255],
[207, 216, 227, 255],
...,
[ 35, 32, 33, 255],
[ 35, 33, 34, 255],
[ 35, 33, 34, 255]],
[[207, 216, 227, 255],
[207, 216, 227, 255],
[207, 215, 227, 255],
...,
[ 35, 33, 33, 255],
[ 35, 33, 34, 255],
[ 35, 33, 34, 255]],
...,
[[ 31, 21, 17, 255],
[ 31, 22, 18, 255],
[ 31, 22, 18, 255],
...,
[ 0, 1, 4, 255],
[ 0, 1, 4, 255],
[ 0, 1, 4, 255]],
[[ 31, 22, 18, 255],
[ 31, 22, 18, 255],
[ 31, 22, 18, 255],
...,
[ 0, 1, 4, 255],
[ 0, 1, 4, 255],
[ 0, 1, 4, 255]],
[[ 31, 22, 18, 255],
[ 30, 22, 17, 255],
[ 31, 22, 18, 255],
...,
[ 0, 1, 4, 255],
[ 0, 1, 4, 255],
[ 0, 1, 4, 255]]], dtype=uint8),
list([{'label': ['Face'], 'notes': '', 'points': [{'x':
0.7053087757313109, 'y': 0.23260437375745527}, {'x':
0.7692307692307693, 'y': 0.36182902584493043}], 'imageWidth': 1280,
'imageHeight': 697}])],
dtype=object)
我只是对什么是 x 和 y 以及如何解决这个问题感到困惑
【问题讨论】:
标签: python numpy tensorflow