Skip to content

Instantly share code, notes, and snippets.

@DibyaranjanSathua
Created February 28, 2019 12:32
Show Gist options
  • Save DibyaranjanSathua/d45b5c4955e79ea6a8cb7b04c028a66d to your computer and use it in GitHub Desktop.
Save DibyaranjanSathua/d45b5c4955e79ea6a8cb7b04c028a66d to your computer and use it in GitHub Desktop.
Test opencv dnn module with tensorflow pre-trained model
import cv2
import numpy as np
def test_dnn_module():
""" Function to test OpenCV DNN module. """
model = 'removed_dropout_graph.pb'
net = cv2.dnn.readNet(model)
img = cv2.imread('F1_R0_A.png')
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgGray = imgGray.astype(np.uint8)
blob = cv2.dnn.blobFromImage(imgGray, 1.0, (28,28), swapRB=True, crop=False)
net.setInput(blob)
output = net.forward()
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment