I currently am using mss to take a screenshot of my screen, and then i convert it into a numpy float 32, my onnx model wants 4 ranks. Im not really understanding how Im not giving it 4 ranks.
This is how i capture the image
<code>import mss
import numpy as np
import win32gui
class WindowCapture():
def __init__(self, windowName):
self.sct = mss.mss()
#finds the window
self.window = win32gui.FindWindow(None, windowName)
if not self.window:
raise Exception('Window not found: {}'.format(windowName))
#gets the coordnates of the window
self.windowPos = win32gui.GetWindowRect(self.window)
def get_screen(self):
# takes a screenshot of the window
screen =
np.array(self.sct.grab(self.windowPos)).astype('float32')
return screen
</code>
<code>import mss
import numpy as np
import win32gui
class WindowCapture():
def __init__(self, windowName):
self.sct = mss.mss()
#finds the window
self.window = win32gui.FindWindow(None, windowName)
if not self.window:
raise Exception('Window not found: {}'.format(windowName))
#gets the coordnates of the window
self.windowPos = win32gui.GetWindowRect(self.window)
def get_screen(self):
# takes a screenshot of the window
screen =
np.array(self.sct.grab(self.windowPos)).astype('float32')
return screen
</code>
import mss
import numpy as np
import win32gui
class WindowCapture():
def __init__(self, windowName):
self.sct = mss.mss()
#finds the window
self.window = win32gui.FindWindow(None, windowName)
if not self.window:
raise Exception('Window not found: {}'.format(windowName))
#gets the coordnates of the window
self.windowPos = win32gui.GetWindowRect(self.window)
def get_screen(self):
# takes a screenshot of the window
screen =
np.array(self.sct.grab(self.windowPos)).astype('float32')
return screen
This is the file that runs the onnx runtime
<code>import numpy as np
import cv2 as cv
import onnxruntime
class unitDetect():
def __init__(self):
self.session = onnxruntime.InferenceSession(model, None)
self.input_name = self.session.get_inputs()[0].name
self.output_name = self.session.get_outputs()[0].name
def runModel(self, source):
result = self.session.run([self.output_name], {self.input_name: source})
pred = int(np.argmax(np.array(result).squeeze(), axis=0))
print(pred)
</code>
<code>import numpy as np
import cv2 as cv
import onnxruntime
class unitDetect():
def __init__(self):
self.session = onnxruntime.InferenceSession(model, None)
self.input_name = self.session.get_inputs()[0].name
self.output_name = self.session.get_outputs()[0].name
def runModel(self, source):
result = self.session.run([self.output_name], {self.input_name: source})
pred = int(np.argmax(np.array(result).squeeze(), axis=0))
print(pred)
</code>
import numpy as np
import cv2 as cv
import onnxruntime
class unitDetect():
def __init__(self):
self.session = onnxruntime.InferenceSession(model, None)
self.input_name = self.session.get_inputs()[0].name
self.output_name = self.session.get_outputs()[0].name
def runModel(self, source):
result = self.session.run([self.output_name], {self.input_name: source})
pred = int(np.argmax(np.array(result).squeeze(), axis=0))
print(pred)
this is the error i get
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Invalid rank for input: images Got: 3 Expected: 4 Please fix either the inputs/outputs or the model.
This is from netron.app and is the input the model wants:
name: images
tensor: float32[1,3,416,416]