Code Monkey home page Code Monkey logo

yolo_service's People

Contributors

johannestang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

yolo_service's Issues

combine with fastapi celery and rabbitmq + video detection

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

Can't start the container

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.

error on uploaded image

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?

README Updates

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.