From 5e21b4acceded2f85359055f2670c24a00ffb0a5 Mon Sep 17 00:00:00 2001 From: Boris Sekachev <40690378+bsekachev@users.noreply.github.com> Date: Tue, 14 Apr 2020 23:21:46 +0300 Subject: [PATCH] Batch of fixes (#1403) * Fixed bug when job cannot be opened * Fixed bug when deactivated shape is still highlighted * Fixed Error: 'AttributeError: 'tuple' object has no attribute 'read' * Fixed: wrong semi-automatic segmentation near edges of an image * Updated changelog Co-authored-by: Nikita Manovich <40690625+nmanovic@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ cvat-ui/src/actions/annotation-actions.ts | 4 +++- .../standard-workspace/canvas-wrapper.tsx | 3 --- .../annotation-page/annotation-page.tsx | 3 ++- cvat-ui/src/reducers/annotation-reducer.ts | 3 +++ cvat-ui/src/reducers/interfaces.ts | 1 + cvat/apps/dextr_segmentation/dextr.py | 18 +++++++++++++----- cvat/apps/reid/reid.py | 4 ++-- 8 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5296ba66..e23603c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - VOC format exports Upper case labels correctly in lower case (https://github.com/opencv/cvat/pull/1379) - Fixed polygon exporting bug in COCO dataset (https://github.com/opencv/cvat/issues/1387) - Task creation from remote files (https://github.com/opencv/cvat/pull/1392) +- Job cannot be opened in some cases when the previous job was failed during opening (https://github.com/opencv/cvat/issues/1403) +- Deactivated shape is still highlighted on the canvas (https://github.com/opencv/cvat/issues/1403) +- AttributeError: 'tuple' object has no attribute 'read' in ReID algorithm (https://github.com/opencv/cvat/issues/1403) +- Wrong semi-automatic segmentation near edges of an image (https://github.com/opencv/cvat/issues/1403) - Git repos paths (https://github.com/opencv/cvat/pull/1400) ### Security diff --git a/cvat-ui/src/actions/annotation-actions.ts b/cvat-ui/src/actions/annotation-actions.ts index 46989db3..8f24bb65 100644 --- a/cvat-ui/src/actions/annotation-actions.ts +++ b/cvat-ui/src/actions/annotation-actions.ts @@ -923,7 +923,9 @@ export function getJobAsync( dispatch({ type: AnnotationActionTypes.GET_JOB, - payload: {}, + payload: { + requestedId: jid, + }, }); const loadJobEvent = await logger.log( diff --git a/cvat-ui/src/components/annotation-page/standard-workspace/canvas-wrapper.tsx b/cvat-ui/src/components/annotation-page/standard-workspace/canvas-wrapper.tsx index 8296f287..53be20c0 100644 --- a/cvat-ui/src/components/annotation-page/standard-workspace/canvas-wrapper.tsx +++ b/cvat-ui/src/components/annotation-page/standard-workspace/canvas-wrapper.tsx @@ -160,9 +160,6 @@ export default class CanvasWrapperComponent extends React.PureComponent { if (prevProps.activatedStateID !== null && prevProps.activatedStateID !== activatedStateID) { canvasInstance.activate(null); - } - - if (activatedStateID) { const el = window.document.getElementById(`cvat_canvas_shape_${prevProps.activatedStateID}`); if (el) { (el as any).instance.fill({ opacity: opacity / 100 }); diff --git a/cvat-ui/src/containers/annotation-page/annotation-page.tsx b/cvat-ui/src/containers/annotation-page/annotation-page.tsx index a47b3572..1a3ed678 100644 --- a/cvat-ui/src/containers/annotation-page/annotation-page.tsx +++ b/cvat-ui/src/containers/annotation-page/annotation-page.tsx @@ -33,6 +33,7 @@ function mapStateToProps(state: CombinedState, own: OwnProps): StateToProps { const { annotation: { job: { + requestedId, instance: job, fetching, }, @@ -41,7 +42,7 @@ function mapStateToProps(state: CombinedState, own: OwnProps): StateToProps { } = state; return { - job: !job || jobID === job.id ? job : null, + job: jobID === requestedId ? job : null, fetching, workspace, }; diff --git a/cvat-ui/src/reducers/annotation-reducer.ts b/cvat-ui/src/reducers/annotation-reducer.ts index 14ac3eb6..3a38ba0a 100644 --- a/cvat-ui/src/reducers/annotation-reducer.ts +++ b/cvat-ui/src/reducers/annotation-reducer.ts @@ -35,6 +35,7 @@ const defaultState: AnnotationState = { }, job: { labels: [], + requestedId: null, instance: null, attributes: {}, fetching: false, @@ -105,6 +106,8 @@ export default (state = defaultState, action: AnyAction): AnnotationState => { ...state, job: { ...state.job, + instance: null, + requestedId: action.payload.requestedId, fetching: true, }, }; diff --git a/cvat-ui/src/reducers/interfaces.ts b/cvat-ui/src/reducers/interfaces.ts index 66110ab7..6c5846e0 100644 --- a/cvat-ui/src/reducers/interfaces.ts +++ b/cvat-ui/src/reducers/interfaces.ts @@ -317,6 +317,7 @@ export interface AnnotationState { }; job: { labels: any[]; + requestedId: number | null; instance: any | null | undefined; attributes: Record; fetching: boolean; diff --git a/cvat/apps/dextr_segmentation/dextr.py b/cvat/apps/dextr_segmentation/dextr.py index db8c71e7..c51eeaba 100644 --- a/cvat/apps/dextr_segmentation/dextr.py +++ b/cvat/apps/dextr_segmentation/dextr.py @@ -48,11 +48,19 @@ class DEXTR_HANDLER: 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) + + # Padding mustn't be more than the closest distance to an edge of an image + [width, height] = numpy_image.shape[:2] + x_values = points[:, 0] + y_values = points[:, 1] + [min_x, max_x] = [np.min(x_values), np.max(x_values)] + [min_y, max_y] = [np.min(y_values), np.max(y_values)] + padding = min(min_x, min_y, width - max_x, height - max_y, _DEXTR_PADDING) bounding_box = ( - max(min(points[:, 0]) - _DEXTR_PADDING, 0), - max(min(points[:, 1]) - _DEXTR_PADDING, 0), - min(max(points[:, 0]) + _DEXTR_PADDING, numpy_image.shape[1] - 1), - min(max(points[:, 1]) + _DEXTR_PADDING, numpy_image.shape[0] - 1) + max(min(points[:, 0]) - padding, 0), + max(min(points[:, 1]) - padding, 0), + min(max(points[:, 0]) + padding, numpy_image.shape[1] - 1), + min(max(points[:, 1]) + padding, numpy_image.shape[0] - 1) ) # Prepare an image @@ -61,7 +69,7 @@ class DEXTR_HANDLER: interpolation = cv2.INTER_CUBIC).astype(np.float32) # Make a heatmap - points = points - [min(points[:, 0]), min(points[:, 1])] + [_DEXTR_PADDING, _DEXTR_PADDING] + points = points - [min(points[:, 0]), min(points[:, 1])] + [padding, padding] points = (points * [_DEXTR_SIZE / numpy_cropped.shape[1], _DEXTR_SIZE / numpy_cropped.shape[0]]).astype(int) heatmap = np.zeros(shape=resized.shape[:2], dtype=np.float64) for point in points: diff --git a/cvat/apps/reid/reid.py b/cvat/apps/reid/reid.py index 876101e1..bf79bac9 100644 --- a/cvat/apps/reid/reid.py +++ b/cvat/apps/reid/reid.py @@ -150,7 +150,7 @@ class ReID: job = rq.get_current_job() box_tracks = {} - next_image = cv2.imdecode(numpy.fromstring(next(self.__frame_iter).read(), numpy.uint8), cv2.IMREAD_COLOR) + next_image = cv2.imdecode(numpy.fromstring((next(self.__frame_iter)[0]).read(), numpy.uint8), cv2.IMREAD_COLOR) for idx, (cur_frame, next_frame) in enumerate(list(zip(frames[:-1], frames[1:]))): job.refresh() if "cancel" in job.meta: @@ -172,7 +172,7 @@ class ReID: continue cur_image = next_image - next_image = cv2.imdecode(numpy.fromstring(next(self.__frame_iter).read(), numpy.uint8), cv2.IMREAD_COLOR) + next_image = cv2.imdecode(numpy.fromstring((next(self.__frame_iter)[0]).read(), numpy.uint8), cv2.IMREAD_COLOR) difference_matrix = self.__compute_difference_matrix(cur_boxes, next_boxes, cur_image, next_image) cur_idxs, next_idxs = linear_sum_assignment(difference_matrix) for idx, cur_idx in enumerate(cur_idxs):