johannestang / yolo_service Goto Github PK
View Code? Open in Web Editor NEWDockerized YOLO object detection service
Dockerized YOLO object detection service
heya!
I got your repo working with videos, its amazing thanks for sharing your code. I found a different repo that included queueing, fastapi and workers. trying to combine your dockerized darknet with it as .so needs to be compiled, but im not that good with docker. wanna trade pokemon and see if we can do some good?
optimally i want to do a generator so the json stream can be grabbed continously, but this is atleast a start!
`def convertBack(x, y, w, h):
xmin = int(round(x - (w / 2)))
xmax = int(round(x + (w / 2)))
ymin = int(round(y - (h / 2)))
ymax = int(round(y + (h / 2)))
return xmin, ymin, xmax, ymax
def cvDrawBoxes(detections, img):
res=""
for detection in detections:
x, y, w, h = detection[2][0],
detection[2][1],
detection[2][2],
detection[2][3]
xmin, ymin, xmax, ymax = convertBack(
float(x), float(y), float(w), float(h))
pt1 = (xmin, ymin)
pt2 = (xmax, ymax)
#res+=detection[0]
return detection[0]
netMain = None
metaMain = None
altNames = None
def YOLO():
global metaMain, netMain, altNames, curframe, hue, saturation, brightness, listcoords
configPath = "./"
weightPath = "./"
metaPath = "./"
if not os.path.exists(configPath):
raise ValueError("Invalid config path " + os.path.abspath(configPath) + "
")
if not os.path.exists(weightPath):
raise ValueError("Invalid weight path " + os.path.abspath(weightPath) + "
")
if not os.path.exists(metaPath):
raise ValueError("Invalid data file path " + os.path.abspath(metaPath) + "
")
if netMain is None:
netMain = darknet.load_net_custom(configPath.encode(
"ascii"), weightPath.encode("ascii"), 0, 1) # batch size = 1
if metaMain is None:
metaMain = darknet.load_meta(metaPath.encode("ascii"))
if altNames is None:
try:
with open(metaPath) as metaFH:
metaContents = metaFH.read()
import re
match = re.search("names *= (.)$", metaContents,
re.IGNORECASE | re.MULTILINE)
if match:
result = match.group(1)
else:
result = None
try:
if os.path.exists(result):
with open(result) as namesFH:
namesList = namesFH.read().strip().split("\n")
altNames = [x.strip() for x in namesList]
except TypeError:
pass
except Exception:
pass
file_to_upload = connexion.request.files['image_file']
fd, filename = tempfile.mkstemp()
file_to_upload.save(filename)
#cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture(filename)
cap.set(3, 1280)
cap.set(4, 720)
darknet_image = darknet.make_image(darknet.network_width(netMain),
darknet.network_height(netMain),3)
res = list()
while cap.isOpened():
ret, frame_read = cap.read()
if not ret:
return json.dumps(res)
start = time.time()
frame_rgb = cv2.cvtColor(frame_read, cv2.COLOR_BGR2RGB)
frame_resized = cv2.resize(frame_rgb,
(darknet.network_width(netMain),
darknet.network_height(netMain)),
interpolation=cv2.INTER_LINEAR)
darknet.copy_image_from_bytes(darknet_image, frame_resized.tobytes())
detections = darknet.detect_image(network, class_names, darknet_image, thresh=0.3, nms=.35)
image = cvDrawBoxes(detections, frame_resized)
res.append(image)
cv2.waitKey(1)
return json.dumps(res)`
/yolo: post: operationId: app.YOLO summary: Perform object detection on uploaded video. consumes: - multipart/form-data parameters: - name: image_file in: formData description: Image type: file required: true - name: threshold in: formData description: Detection threshold type: number minimum: 0 maximum: 1 default: 0.25 responses: 200: description: Returns detections, confidences and coordinates.
heres what i followed:
https://github.com/GregaVrbancic/fastapi-celery
I would like to use this repo but with yolov4, is it possible?
I tried to change the dockerfile in this way:
from this: RUN git clone -n https://github.com/AlexeyAB/darknet.git
to this: RUN git clone https://github.com/AlexeyAB/darknet.git
and comment the line
#RUN git checkout 4c315ea26b56c2bf20ebc240d94386c6e3cc83db
but the image wants to start.
Do you have any suggestions?
Thank you,
Sam.
All I'm getting in the log is
Try to load cfg: data/yolov3.cfg, weights: yolov3.weights, clear = 0
and then the container stops.
I'm trying to test it on my Synology DS918+ NAS.
Hey man! awesome stuff and great tutorial.
I get everything working except inference on uploaded image.
It throws this error message:
Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
any idea what that could be?
Thank you for this image!
README states:
YOLO9000 covering more than 9000 classes listed here. Tag: yolo90000.
Tag should be yolo9000
Also, some simple python examples may be helpful, here's one for POST:
import requests
import json
with open('test.jpg', 'rb') as f:
r = requests.post("http://localhost:9999/detect",files={'image_file': f},timeout=60, data={'threshold':0.25})
if r.status_code == 200:
data = json.loads(r.text)
print(data)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.