【发布时间】:2022-06-12 09:47:48
【问题描述】:
我使用迁移学习 (InceptionV3) 训练了一个模型,当我尝试预测它显示的结果时:
ValueError: cannot reshape array of size 921600 into shape (224,224,3)
我用来训练模型的图像生成器是:
root_dir = 'G:/Dataset'
img_generator_flow_train = img_generator.flow_from_directory(
directory=root_dir,
target_size=(224,224),
batch_size=32,
shuffle=True,
subset="training")
img_generator_flow_valid = img_generator.flow_from_directory(
directory=root_dir,
target_size=(224,224),
batch_size=32,
shuffle=True,
subset="validation")
base_model = tf.keras.applications.InceptionV3(input_shape=(224,224,3),
include_top=False,
weights = "imagenet"
)
实现代码为:
cap=cv.VideoCapture(0)
facedetect=cv.CascadeClassifier(cv.data.haarcascades + 'haarcascade_frontalface_default.xml')
model=load_model('Signmodel.h5')
while cap.isOpened():
sts,frame=cap.read()
if sts:
faces=facedetect.detectMultiScale(frame,1.3,5)
for x,y,w,h in faces:
y_pred=model.predict(frame)
print(y_pred,"printing y_pred")
cv.putText(frame,y_pred,(x,y-30), cv.FONT_HERSHEY_COMPLEX, 0.75, (255,0,0),1, cv.LINE_AA)
我试图调整框架的大小:
frame=cv.resize(frame,(224,224),3)
但这样做时我得到了:
ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(32, 224, 3)
我应该怎么做才能解决这个问题?
谢谢!!!
【问题讨论】:
-
请完成回溯。然后你需要
cv.resize,因为你的frame不是(224,224,3)的形状并且不能重新调整为那个形状,它必须调整为图像的大小 -
如果 cap.read() 返回 numpy 数组,我应该如何将框架调整为图像? Github链接:github.com/Nehasatya/sign-language-translator.git
-
224*224*3=150528,不是 921600
标签: python tensorflow opencv keras deep-learning