0

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.

Tiger-222
  • 6,677
  • 3
  • 47
  • 60
Legion
  • 454
  • 2
  • 7
  • 17
  • did you actually read the error message? – 00__00__00 Apr 16 '18 at 05:08
  • YES, I don’t understand it and more importantly- I don’t know how to fix it. If I did - I wouldn’t be wasting my time here... – Legion Apr 16 '18 at 05:34
  • @MonkeyBot2020, please, be polite. Nobody is going to "waste their time" for your questions with such attitude. – Andriy Makukha Apr 17 '18 at 06:09
  • Courtesy works both ways. In either case, if you think this is a waste of time, then don't read or reply to this question - no one is forcing you... :) – Legion Apr 18 '18 at 07:22

1 Answers1

1

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

00__00__00
  • 4,834
  • 9
  • 41
  • 89