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

OpenVINO auto annotation mode (import issue) #516

Closed
bouziady opened this issue Jun 24, 2019 · 32 comments
Closed

OpenVINO auto annotation mode (import issue) #516

bouziady opened this issue Jun 24, 2019 · 32 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@bouziady
Copy link

Hi All, Hi @nmanovic,

I want to run my custom yolov3 models in auto annotation mode in CVAT
So, I converted my model to IR format with OpenVINO, now I m trying to submit the 4 necessary files (.xml, .bin, .json and interpret.py) to the server. but I have some issues with the interpretation script .py:
Test Failed : import not found

ss

Does any one have any idea how to solve this ?
does anyone have an interpretation script for yolov3-tiny (1 classe) ?

@nmanovic
Copy link
Contributor

@BOUKARY , it seems you use import statement in your script. For now it is prohibited. With help of @benhoff it should be fixed soon. See the PR for more details: #514

@bouziady
Copy link
Author

Thanks for replying @nmanovic

Yes, you 're right I have "import" in my interpretation script. But when I remove them I still got the same error.

this is my original script with imports :

import numpy as np
import cv2

conf_threshold = 0.25
nms_threshold = 0.4

def clip(value):
return max(min(1.0, value), 0.0)

for frame_results in detections:
frame_height = frame_results["frame_height"]
frame_width = frame_results["frame_width"]
frame_number = frame_results["frame_id"]

for out in frame_results["detections"]:
	for detection in out.all():
		scores = detection[5:]
		class_id = 0#np.argmax(scores)
		confidence = scores[class_id]
		if confidence > conf_threshold:
			center_x = int(detection[0] * width)
			center_y = int(detection[1] * height)
			w = int(detection[2] * width)
			h = int(detection[3] * height)
			# if self.box_min_size > (w,h):
			#   continue
			x = int(center_x - w / 2)
			y = int(center_y - h / 2)
			class_ids.append(class_id)
			confidences.append(float(confidence))
			boxes.append([x, y, w, h])

indices = cv2.dnn.NMSBoxes(boxes, confidences, conf_threshold, nms_threshold)

for i in indices:
	i = i[0]

	results.add_box(
		xtl=clip(boxes[i][0]),
		ytl=clip(boxes[i][1]),
		xbr=clip(boxes[i][0] + boxes[i][2]),
		ybr=clip(boxes[i][1] + boxes[i][3]),
		label=int(class_ids[i]),
		frame_number=frame_number,
		attributes={
		"confidence": "{:.2f}".format(confidences[i]),
		},
	)

this is my new script without imports :

def clip(value):
return max(min(1.0, value), 0.0)

for frame_results in detections:
frame_height = frame_results["frame_height"]
frame_width = frame_results["frame_width"]
frame_number = frame_results["frame_id"]

for out in frame_results["detections"]:
	for detection in out.all():
		scores = detection[5:]
		class_id = 0#np.argmax(scores)
		confidence = scores[class_id]
		if confidence > 0.25:
			center_x = int(detection[0] * width)
			center_y = int(detection[1] * height)
			w = int(detection[2] * width)
			h = int(detection[3] * height)
			# if self.box_min_size > (w,h):
			#   continue
			x = int(center_x - w / 2)
			y = int(center_y - h / 2)
			class_ids.append(class_id)
			confidences.append(float(confidence))
			boxes.append([x, y, w, h])

			results.add_box(
				xtl=clip(x),
				ytl=clip(y),
				xbr=clip(x + w),
				ybr=clip(y + h),
				label=int(class_id),
				frame_number=frame_number,
				attributes={
				"confidence": "{:.2f}".format(confidence),
				},
			)

is there any other solution to use yolo custom model with cvat auto annotation model ?

@nmanovic
Copy link
Contributor

@BOUKARY , could you please attach json, py files? Also need your bin and xml files. We will look on our side.

@benhoff
Copy link
Contributor

benhoff commented Jun 25, 2019

@BOUKARY , it seems you use import statement in your script. For now it is prohibited. With help of @benhoff it should be fixed soon. See the PR for more details: #514

@nmanovic, looks like with my local testing that #514 actually won't let you import new modules in code. Looks like a byproduct of the exec command/process. See this stackoverflow post for a flavor of it.

Once #514 lands, I'll try to go back and allow importing in.

@bouziady
Copy link
Author

These are the files I tried to upload

Please remove ".txt" from filename, github doesnt support these extensions. bin file is to big, github doesnt let me upload it
There are 2 .py files , none of them works.

frozen_darknet_yolov3_model.xml.txt
interpret.py.txt
label_map.json.txt
test.py.txt

@bouziady
Copy link
Author

@benhoff even with a script without import, it gives the same error.

@bouziady bouziady reopened this Jun 25, 2019
@bouziady bouziady reopened this Jun 25, 2019
@nmanovic
Copy link
Contributor

@BOUKARY , if you can share weights using other methods it will be easy for us to debug. Did you use the repo https://github.com/ultralytics/yolov3?

@nmanovic nmanovic added the enhancement New feature or request label Jun 27, 2019
@nmanovic nmanovic added this to the 0.5.0 - Beta milestone Jun 27, 2019
@benhoff
Copy link
Contributor

benhoff commented Jun 29, 2019

@BOUKARY What's the latest error you are getting and what version of openvino are you using?

@benhoff
Copy link
Contributor

benhoff commented Jul 9, 2019

#545 should allow the original poster to use any version of openvino that they desire by uploading a custom preprocessing.py script to account for differences in OpenVino 2019.

@bouziady
Copy link
Author

bouziady commented Jul 9, 2019

Sorry for the late reply
@nmanovic i m using this yolov3 implementation (AlexeyAB)
I have sent all the files to this email address ([email protected]), I hope it s yours

@benhoff i m using l_openvino_toolkit_p_2019.1.144 (openvino 2019 R1.1), Build date:14 May 2019. it s the last version in intel website.

@benhoff

This comment has been minimized.

@benhoff
Copy link
Contributor

benhoff commented Jul 15, 2019

@BOUKARY can you try the latest version of Cvat? There's better support for error messages now and openvino 2019 support included now.

@nmanovic
Copy link
Contributor

It should work in develop branch.

@ThomasBomjan
Copy link

ThomasBomjan commented Aug 18, 2019

I also had a similar error. I ran a custom yolov3 model.(.xml, .bin, .json and interpret.py). I got this error: Checking request has returned the "failed" status. Message: Exception: Model was not properly created/updated. Test failed: Expecting property name enclosed in double quotes: line 20 column 5 (char 474)

@nmanovic
Copy link
Contributor

@ThomasBomjan , please use https://github.com/opencv/cvat/blob/develop/utils/auto_annotation/run_model.py script to debug your files.

@ThomasBomjan
Copy link

Hi @nmanovic Thank you for the script. I followed it up and ran the script. From here as well https://github.com/benhoff/cvat/tree/show-images/utils/auto_annotation. I got importErro : No module

python3 utils/auto_annotation/run_model.py --py ~/Downloads/Models/script_yolo.py --xml ~/Downloads/darknet_yolov3_model.xml --bin ~/Downloads/darknet_yolov3_model.bin --json /Downloads/test.json
Traceback (most recent call last):
File "
/cvat/cvat/settings/base.py", line 33, in
from keys.secret_key import SECRET_KEY
ImportError: No module named 'keys'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "utils/auto_annotation/run_model.py", line 10, in
django.setup()
File "/usr/local/lib/python3.5/dist-packages/django/init.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python3.5/dist-packages/django/conf/init.py", line 79, in getattr
self._setup(name)
File "/usr/local/lib/python3.5/dist-packages/django/conf/init.py", line 66, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.5/dist-packages/django/conf/init.py", line 157, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 665, in exec_module
File "", line 222, in _call_with_frames_removed
File "/cvat/cvat/settings/production.py", line 5, in
from .base import *
File "
/cvat/cvat/settings/base.py", line 36, in
with open(os.path.join(BASE_DIR, 'keys', 'secret_key.py'), 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: '~/cvat/keys/secret_key.py'

@nmanovic
Copy link
Contributor

@ThomasBomjan , we will fix the script. It should not require settings for sure.

@benhoff
Copy link
Contributor

benhoff commented Aug 19, 2019

@ThomasBomjan #650 should fix your above issue. Can you pull the latest code down and try again?

@ThomasBomjan
Copy link

@benhoff I pulled the code and tried it again.I end up getting similar kind of error. I have hunch that it is due to interpretation script. Still cannot figure it out what I am missing

@ThomasBomjan
Copy link

@BOUKARY Hi, Did you solve this problem with above mention interpretation script?

@ThomasBomjan
Copy link

with arguments or without argumenst I am getting same error
python3 new_run_model.py
Traceback (most recent call last):
File "/home/cvat/utils/auto_annotation/../../cvat/settings/base.py", line 33, in
from keys.secret_key import SECRET_KEY
ModuleNotFoundError: No module named 'keys'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "new_run_model.py", line 16, in
from cvat.apps.auto_annotation.inference import run_inference_engine_annotation
File "/home/cvat/utils/auto_annotation/../../cvat/apps/auto_annotation/init.py", line 6, in
from cvat.settings.base import JS_3RDPARTY, CSS_3RDPARTY
File "/home/cvat/utils/auto_annotation/../../cvat/settings/base.py", line 36, in
with open(os.path.join(BASE_DIR, 'keys', 'secret_key.py'), 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/marduk/utils/auto_annotation/../../keys/secret_key.py

@nmanovic
Copy link
Contributor

@ThomasBomjan , you need to update your develop branch. The problem was fixed recently.

@nmanovic
Copy link
Contributor

nmanovic commented Aug 20, 2019

@ThomasBomjan , it seems the problem can be reproduced. As a workaround for now you can create /home/marduk/utils/auto_annotation/../../keys/secret_key.py empty file. Probably it will work. In the future will fix that completely.

@ThomasBomjan
Copy link

ThomasBomjan commented Aug 20, 2019

I build docker-compose again and run the script. Still I am having same issues.
Creating keys/secret_key.py also, Did not work? because it stll lookc for, ImportError: cannot import name 'SECRET_KEY'

@peyman-sabouri
Copy link

I think there is a problem with python libraries, I get this error with python3.7 and get other error with python3.5. Should we create a virtualenv?

@ThomasBomjan
Copy link

@peyman-sabouri what were your errors?

@peyman-sabouri
Copy link

@ThomasBomjan

python2: cvat/utils/auto_annotation/../../cvat/init.py", line 6, in
from cvat.utils.version import get_version
ImportError: No module named utils.version

python3:
with open(os.path.join(BASE_DIR, 'keys', 'secret_key.py'), 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: '~/cvat/utils/auto_annotation/../../keys/secret_key.py'

@peyman-sabouri
Copy link

I created key/secret_key.py and included:

import os
SECRET_KEY = os.environ['SECRET_KEY']

now I am getting this error:

from cvat.apps.auto_annotation.inference_engine import make_plugin, make_network

File "/cvat/utils/auto_annotation/../../cvat/apps/auto_annotation/inference_engine.py", line 5, in
from openvino.inference_engine import IENetwork, IEPlugin
ImportError: No module named 'openvino'

@peyman-sabouri
Copy link

I solved my problem:

copied run_model.py to cvat/apps/auto_annotation/run_model.py

docker exec -it cvat bash -ic 'python3 ~/cvat/apps/auto_annotation/run_model.py --py t1.py --xml yolov3.xml --bin yolov3.bin --json label_map.json'

@bouziady
Copy link
Author

@BOUKARY Hi, Did you solve this problem with above mention interpretation script?

Hi @ThomasBomjan, sorry for the late reply. Nop, i didn't have time to check the last version of CVAT. I had a different error: Import failed error. Not like yours
At the end, i just run my custom yolov3 model through a video, save the predictions results in an XML file in CVAT format, then I upload it to CVAT tool.

@gwestner94
Copy link

Hi @BOUKARY did you manage to get a interp.py working after this, or did you stay with a manual upload?

@bouziady
Copy link
Author

bouziady commented Sep 3, 2019

Hi @BOUKARY did you manage to get a interp.py working after this, or did you stay with a manual upload?

I did it manually to train my model, now i m testing. But i will definitely need this option in the future. I m planning to train a new model for pedestrian counting. The auto annotation will definitely accelerate the labeling process

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

No branches or pull requests

6 participants