我尝试创建一个简单的程序来捕捉屏幕截图(使用mss),并获取tensorflow来预测/检测图像中的元素,但它不起作用。下面是代码的一部分:
import cv2
import mss
import numpy as np
from PIL import Image
#Import TFNet
from darkflow.net.build import TFNet
import matplotlib.pyplot as plt
#Specify the dictonary.
options = {
'model':'cfg/yolo.cfg',
'load':'bin/yolov2.weights',
'threshold': 0.3
}
tfnet = TFNet(options)
#Creates an endless loop for high-speed image acquisition...
while (True):
with mss.mss() as sct:
#Get raw pixels from the screen
sct_img = sct.grab(sct.monitors[1])
#Convert image to a numpy array
img = np.array(sct_img)
result = tfnet.return_predict(img)
print(result)有人能告诉我哪里出了问题吗?它每次都返回以下错误:
ValueError: Cannot feed value of shape (1, 608, 608, 4) for Tensor 'input:0', which has shape '(?, 608, 608, 3)'请给出代码示例。提前谢谢。
发布于 2018-04-18 06:50:14
似乎您的输入数据具有与预期不同的形状:
(1, 608, 608, 4) 而不是
(?, 608, 608, 3)你说的好像是图像。通常彩色图像是用RGB编码的,因此有3个通道。您可能需要从数据中删除alpha/透明性通道。
https://stackoverflow.com/questions/49841971
复制相似问题