Skip to content

Commit

Permalink
Az/fix dextr (#1348)
Browse files Browse the repository at this point in the history
* Fixed dextr_segmentation app

* updated changelog

Co-authored-by: Nikita Manovich <[email protected]>
  • Loading branch information
azhavoro and nmanovic authored Apr 3, 2020
1 parent be2ec3a commit 7bdf9bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- New shape is added when press ``esc`` when drawing instead of cancellation
- Fixed dextr segmentation.
- Fixed `FileNotFoundError` during dump after moving format files

### Security
Expand Down
7 changes: 5 additions & 2 deletions cvat/apps/dextr_segmentation/dextr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-License-Identifier: MIT

from cvat.apps.auto_annotation.inference_engine import make_plugin_or_core, make_network
from cvat.apps.engine.frame_provider import FrameProvider

import os
import cv2
Expand All @@ -29,7 +30,7 @@ def __init__(self):
raise Exception("DEXTR_MODEL_DIR is not defined")


def handle(self, im_path, points):
def handle(self, db_data, frame, points):
# Lazy initialization
if not self._plugin:
self._plugin = make_plugin_or_core()
Expand All @@ -42,7 +43,9 @@ def handle(self, im_path, points):
else:
self._exec_network = self._plugin.load(network=self._network)

image = PIL.Image.open(im_path)
frame_provider = FrameProvider(db_data)
image = frame_provider.get_frame(frame, frame_provider.Quality.ORIGINAL)
image = PIL.Image.open(image[0])
numpy_image = np.array(image)
points = np.asarray([[int(p["x"]), int(p["y"])] for p in points], dtype=int)
bounding_box = (
Expand Down
10 changes: 4 additions & 6 deletions cvat/apps/dextr_segmentation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

import django_rq
import json
import os
import rq

__RQ_QUEUE_NAME = "default"
__DEXTR_HANDLER = DEXTR_HANDLER()

def _dextr_thread(im_path, points):
def _dextr_thread(db_data, frame, points):
job = rq.get_current_job()
job.meta["result"] = __DEXTR_HANDLER.handle(im_path, points)
job.meta["result"] = __DEXTR_HANDLER.handle(db_data, frame, points)
job.save_meta()


Expand All @@ -38,8 +37,7 @@ def create(request, jid):
slogger.job[jid].info("create dextr request for the JOB: {} ".format(jid)
+ "by the USER: {} on the FRAME: {}".format(username, frame))

db_task = Job.objects.select_related("segment__task").get(id=jid).segment.task
im_path = os.path.realpath(db_task.get_frame_path(frame))
db_data = Job.objects.select_related("segment__task__data").get(id=jid).segment.task.data

queue = django_rq.get_queue(__RQ_QUEUE_NAME)
rq_id = "dextr.create/{}/{}".format(jid, username)
Expand All @@ -53,7 +51,7 @@ def create(request, jid):
job.delete()

queue.enqueue_call(func=_dextr_thread,
args=(im_path, points),
args=(db_data, frame, points),
job_id=rq_id,
timeout=15,
ttl=30)
Expand Down

0 comments on commit 7bdf9bb

Please sign in to comment.