Created
December 19, 2018 11:21
-
-
Save previtus/bbecf03ae2ab1e952eb6cde26dd85638 to your computer and use it in GitHub Desktop.
simple_darkflow_tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [SETUP, get these:] | |
# built_graph/yolo.meta | |
# built_graph/yolo.pb | |
# (using # flow --model cfg/yolo.cfg --load bin/yolo.weights --savepb) | |
from darkflow.net.build import TFNet | |
import numpy | |
import os, fnmatch, random | |
import cv2 | |
def load_model(): | |
options = {#"model": "cfg/yolo.cfg", | |
#"load": "bin/yolo.weights", | |
"pbLoad": "built_graph/yolo.pb", | |
"metaLoad": "built_graph/yolo.meta", | |
"threshold": 0.3, | |
"gpu": 0.8} | |
tfnet = TFNet(options) | |
return tfnet | |
def convert_numpy_floats(result): | |
# model result contains list of dictionaries, which have problematic data structure of numpy.float32 | |
# (in confidence). Lets convert these to me JSON-able | |
for item in result: | |
for key in item.keys(): | |
if isinstance(item[key], numpy.float32): | |
item[key] = float(item[key]) | |
return result | |
def run_on_image(image_object, model): | |
result = model.return_predict(image_object) | |
result = convert_numpy_floats(result) | |
return result | |
image_url = "https://www.arlingtondogandcat.com/imagebank/eVetSites/DogCats/052016_EVS_CatDog5.jpg" | |
image_path = "testimg.jpg" | |
import urllib.request | |
urllib.request.urlretrieve(image_url, image_path) | |
print("Downloaded the image ...") | |
image_object = cv2.imread(image_path) | |
darkflow_model = load_model() | |
print("Loaded Darkflow model ...") | |
result = run_on_image(image_object, darkflow_model) | |
print("Finished with the image ...") | |
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [SETUP, get these:] | |
# built_graph/yolo.meta | |
# built_graph/yolo.pb | |
# (using # flow --model cfg/yolo.cfg --load bin/yolo.weights --savepb) | |
# testimg.jpg | |
from darkflow.net.build import TFNet | |
import cv2 | |
options = {"pbLoad": "built_graph/yolo.pb", | |
"metaLoad": "built_graph/yolo.meta", | |
"threshold": 0.3, | |
"gpu": 0.8} | |
model = TFNet(options) | |
image_path = "testimg.jpg" | |
image_object = cv2.imread(image_path) | |
result = model.return_predict(image_object) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment