I tried to create a simple program which captures screenshots (using mss) and gets tensorflow to predict/detect elements in the images, but it's not working. Here's part of the code:
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)
Could someone tell me where I'm going wrong? It returns the following error every time:
ValueError: Cannot feed value of shape (1, 608, 608, 4) for Tensor 'input:0', which has shape '(?, 608, 608, 3)'
Please give code examples. Thanks in advance.
it seems that your input data have different shape than expected:
(1, 608, 608, 4)
instead of
(?, 608, 608, 3)
It seems you are talking about images. Usually color images are encoded in RGB hence 3 channels. You probably need to remove the alpha/transparency channel from your data