Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy Custom Trained Weights with Web Application #2969

Open
amar-mustaqim opened this issue Apr 18, 2019 · 13 comments
Open

Deploy Custom Trained Weights with Web Application #2969

amar-mustaqim opened this issue Apr 18, 2019 · 13 comments
Labels

Comments

@amar-mustaqim
Copy link

amar-mustaqim commented Apr 18, 2019

Hi, i'm still a beginner in darknet. I've trained my own weights and i have doubts on how to implement it on web application because i just know how to execute the detection on the command line. Any help?

@AlexeyAB
Copy link
Owner

@amar-mustaqim Hi,

If you know how to do web-application in Python, then you can base it on examples:
https://github.com/AlexeyAB/darknet/blob/master/darknet.py
https://github.com/AlexeyAB/darknet/blob/master/darknet_video.py

Do you want to detect objects on images or video-stream from IP-camera?

@amar-mustaqim
Copy link
Author

Thanks for your suggestion. I want to detect objects on video stream of my web application.

Do i need to change the path in the code with my path?

And do i need to retrain the weights?

@AlexeyAB
Copy link
Owner

Thanks for your suggestion. I want to detect objects on video stream of my web application.

Just run this command:
./darknet detector demo ./cfg/coco.data ./cfg/yolov3.cfg ./yolov3.weights rtsp://login:password@192.168.0.228:554 -json_port 8070 -mjpeg_port 8090 -ext_output -dont_show

or
./darknet detector demo ./cfg/coco.data ./cfg/yolov3.cfg ./yolov3.weights http://192.168.0.80:8080/video?dummy=param.mjpg -json_port 8070 -mjpeg_port 8090 -ext_output -dont_show

So the Darknet will work as server, so you can connect to them by using Chrome/Firefox Web-Browser to ports 8070 and 8090.

Do i need to change the path in the code with my path?

You shouldn't change source code.

And do i need to retrain the weights?

If you want to detect these objects, then you shouldn't retrain it: https://github.com/AlexeyAB/darknet/blob/master/data/coco.names

@amar-mustaqim
Copy link
Author

Is this also works if i want to detect the objects from the webcam? Let say if my web application have a webcam features and the output will be display on the web app during the detection

@AlexeyAB
Copy link
Owner

Yes, for web-cam use this command
./darknet detector demo ./cfg/coco.data ./cfg/yolov3.cfg ./yolov3.weights -c 0 -json_port 8070 -mjpeg_port 8090 -ext_output -dont_show

where is -c 0 is for Web-camera number 0.

So you can just create a static HTML page and add iframe, for example:

<head>
    <title>HTML iframe</title>
</head>
<body>
    <iframe src="http://your-site:8090" width="100%" height="100%" frameborder="1"> </iframe>
    <iframe src="http://your-site:8070" width="100%" height="100%" frameborder="1"> </iframe>
</body>
</html>

You can test it on your PC.

  • Create such page.html file with such content:
<head>
    <title>HTML iframe</title>
</head>
<body>
    <iframe src="http://localhost:8090" width="100%" height="100%" frameborder="1"> </iframe>

    <iframe src="http://localhost:8070" width="100%" height="100%" frameborder="1"> </iframe>
</body>
</html>
  • Get somewhere any videofile test.mp4

  • Run this command:
    ./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights test.mp4 -mjpeg_port 8090 -json_port 8070 -dont_show -ext_output

  • And open your page.html in the Web-browser Chrome/Firefox (isn't tested on IE)

@DeeeepNet
Copy link

DeeeepNet commented Apr 19, 2019

Hi @AlexeyAB,
I want to use my own trained model in production, I have a camera that captures the images, and I want sometimes give the images to the model, and I can't use ./darknet ..... using the terminal, I want to use the model within python codes, I want to be such this structure:
.......
model = None
........
if model is None:
model = My_model(weights)
........
if ok:
predict = model(image)
......

@amar-mustaqim
Copy link
Author

Thank you so much @AlexeyAB for your quick response and good explanations. You are very awesome!

@amar-mustaqim
Copy link
Author

amar-mustaqim commented Apr 20, 2019

darknet.exe detector demo data/obj.data yolo-obj.cfg backup/yolo-obj_last.weights -c 0 -mjpeg_port 8090 -json_port 8070 -dont_show -ext_output

@AlexeyAB I use this command to detect my weights and it seems running well:
jpeg_stream

and i try to use flask to develop the web:
main code

but when I try to execute it on the web while the command line is running, this error occur:
output1 - this when i just add :8090 and :8070
page

output2 - this when i try to add http that u specify and my site address code2

am i missing something?

@AlexeyAB
Copy link
Owner

Why did you doubled http and port number

Use http://127.0.0.1:8090

@maria-mh07
Copy link

Hi, I´m still a beginner in darknet and I want to detect objects on images from JSON server. I tried:

darknet detector test data/coco.data cfg/yolov3.cfg backup/yolov3.weights -thresh 0.6 -json_port 8070 -ext_output -dont_show data/img/horses.jpg

but it does not work. Any help?

@AlexeyAB
Copy link
Owner

@maria-mh07
-json_port 8070 work only for Video (camera, stream, file, ...), not for image

If you want to use JSON-server for images - you should implement it by yourself by using Darknet as library.

@maria-mh07
Copy link

ok @AlexeyAB thank you!

@varungupta31
Copy link

@amar-mustaqim I'm looking to implement something like this! Did you train the model locally? ( I trained it on colab) and am new to Flask, can you please provide the code so I can learn how deployment of yolo4 is done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants