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

feature/76_add_statistics_about_the_labeled_objects #268

Draft
wants to merge 16 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ copyright: Copyright © 2019 Piotr Skalski

# Customization
extra:
version: 1.8.0-alpha
version: 1.9.0-alpha
social:
- icon: fontawesome/brands/github
link: https://github.com/SkalskiP
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "make-sense",
"version": "1.0.0",
"version": "1.9.0-alpha",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.3",
Expand Down
Binary file added public/ico/poll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/ico/stats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/data/enums/Notification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export enum Notification {
EMPTY_LABEL_NAME_ERROR = 0,
NON_UNIQUE_LABEL_NAMES_ERROR = 1
NON_UNIQUE_LABEL_NAMES_ERROR = 1,
ABOUT_TO_REMOVE_USED_LABEL_NAME_WARNING = 2,
REMOVED_USED_LABEL_NAME_WARNING = 3
}
3 changes: 2 additions & 1 deletion src/data/enums/PopupWindowType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export enum PopupWindowType {
IMPORT_ANNOTATIONS = 'IMPORT_ANNOTATIONS',
INSERT_LABEL_NAMES = 'INSERT_LABEL_NAMES',
EXIT_PROJECT = 'EXIT_PROJECT',
LOADER = 'LOADER'
LOADER = 'LOADER',
PER_LABEL_ID_COUNTS_STATISTICS = 'PER_LABEL_ID_COUNTS_STATISTICS'
}
39 changes: 32 additions & 7 deletions src/data/info/DropDownMenuData.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {updateActivePopupType} from '../../store/general/actionCreators';
import {PopupWindowType} from '../enums/PopupWindowType';
import {store} from '../../index';
import {LabelsSelector} from '../../store/selectors/LabelsSelector';

export type DropDownMenuNode = {
name: string
description?: string
imageSrc: string
imageAlt: string
disabled: boolean
disabled: (() => boolean) | boolean
onClick?: () => void
children?: DropDownMenuNode[]
}
Expand All @@ -20,39 +21,39 @@ export const DropDownMenuData: DropDownMenuNode[] = [
disabled: false,
children: [
{
name: 'Edit Labels',
name: 'Edit labels',
description: 'Modify labels list',
imageSrc: 'ico/tags.png',
imageAlt: 'labels',
disabled: false,
onClick: () => store.dispatch(updateActivePopupType(PopupWindowType.UPDATE_LABEL))
},
{
name: 'Import Images',
name: 'Import images',
description: 'Load more images',
imageSrc: 'ico/camera.png',
imageAlt: 'images',
disabled: false,
onClick: () => store.dispatch(updateActivePopupType(PopupWindowType.IMPORT_IMAGES))
},
{
name: 'Import Annotations',
name: 'Import annotations',
description: 'Import annotations from file',
imageSrc: 'ico/import-labels.png',
imageAlt: 'import-labels',
disabled: false,
onClick: () => store.dispatch(updateActivePopupType(PopupWindowType.IMPORT_ANNOTATIONS))
},
{
name: 'Export Annotations',
name: 'Export annotations',
description: 'Export annotations to file',
imageSrc: 'ico/export-labels.png',
imageAlt: 'export-labels',
disabled: false,
onClick: () => store.dispatch(updateActivePopupType(PopupWindowType.EXPORT_ANNOTATIONS))
},
{
name: 'Load AI Model',
name: 'Load AI model',
description: 'Load our pre-trained annotation models',
imageSrc: 'ico/ai.png',
imageAlt: 'load-ai-model',
Expand All @@ -61,6 +62,22 @@ export const DropDownMenuData: DropDownMenuNode[] = [
},
]
},
{
name: 'Insights',
imageSrc: 'ico/stats.png',
imageAlt: 'insights',
disabled: false,
children: [
{
name: 'Label distribution',
description: 'Display per label name annotations count',
imageSrc: 'ico/tags.png',
imageAlt: 'label-distribution',
disabled: () => LabelsSelector.getLabelNames().length === 0,
onClick: () => store.dispatch(updateActivePopupType(PopupWindowType.PER_LABEL_ID_COUNTS_STATISTICS))
},
]
},
{
name: 'Community',
imageSrc: 'ico/plant.png',
Expand All @@ -76,12 +93,20 @@ export const DropDownMenuData: DropDownMenuNode[] = [
onClick: () => window.open('https://skalskip.github.io/make-sense', '_blank')
},
{
name: 'Bugs and Features',
name: 'Bugs and features',
description: 'Report a bug or propose a new feature',
imageSrc: 'ico/bug.png',
imageAlt: 'bug',
disabled: false,
onClick: () => window.open('https://github.com/SkalskiP/make-sense/issues', '_blank')
},
{
name: 'Vote for next BIG feature',
description: 'Vote for next big feature that we will add to Make Sense',
imageSrc: 'ico/poll.png',
imageAlt: 'vote',
disabled: false,
onClick: () => window.open('https://github.com/SkalskiP/make-sense/discussions/269', '_blank')
}
]
}
Expand Down
6 changes: 6 additions & 0 deletions src/data/info/NotificationsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ export const NotificationsDataMap = {
header: 'Non unique label names',
description: 'Looks like not all your label names are unique. Unique names are necessary to guarantee correct' +
' data export when you complete your work. Make your names unique and try again.'
},
[Notification.ABOUT_TO_REMOVE_USED_LABEL_NAME_WARNING]: {
header: 'Used label names',
description: 'Looks like you are about to remove label name that is currently used by some of your annotations. ' +
'Keep in mind that annotations without specified label name can not be exported. You can still abort by ' +
'pressing "Cancel".'
}
}
9 changes: 2 additions & 7 deletions src/logic/render/LineRenderEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import {EditorActions} from '../actions/EditorActions';
import {LabelsSelector} from '../../store/selectors/LabelsSelector';
import {DrawUtil} from '../../utils/DrawUtil';
import {GeneralSelector} from '../../store/selectors/GeneralSelector';
import { v4 as uuidv4 } from 'uuid';
import {ILine} from '../../interfaces/ILine';
import {LineUtil} from '../../utils/LineUtil';
import {updateCustomCursorStyle} from '../../store/general/actionCreators';
import {CustomCursorStyle} from '../../data/enums/CustomCursorStyle';
import {LineAnchorType} from '../../data/enums/LineAnchorType';
import {Settings} from '../../settings/Settings';
import {LabelUtil} from '../../utils/LabelUtil';

export class LineRenderEngine extends BaseRenderEngine {

Expand Down Expand Up @@ -203,12 +203,7 @@ export class LineRenderEngine extends BaseRenderEngine {
const lineOnImage = RenderEngineUtil.transferLineFromViewPortContentToImage(lineOnCanvas, data);
const activeLabelId = LabelsSelector.getActiveLabelNameId();
const imageData: ImageData = LabelsSelector.getActiveImageData();
const labelLine: LabelLine = {
id: uuidv4(),
labelId: activeLabelId,
line: lineOnImage,
isVisible: true
};
const labelLine: LabelLine = LabelUtil.createLabelLine(activeLabelId, lineOnImage);
imageData.labelLines.push(labelLine);
store.dispatch(updateImageDataById(imageData.id, imageData));
store.dispatch(updateFirstLabelCreatedFlag(true));
Expand Down
63 changes: 53 additions & 10 deletions src/utils/LabelUtil.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import {Annotation, LabelName, LabelPoint, LabelPolygon, LabelRect} from '../store/labels/types';
import { v4 as uuidv4 } from 'uuid';
import {find} from 'lodash';
import {Annotation, ImageData, LabelLine, LabelName, LabelPoint, LabelPolygon, LabelRect} from '../store/labels/types';
import {v4 as uuidv4} from 'uuid';
import {find, sample} from 'lodash';
import {IRect} from '../interfaces/IRect';
import {LabelStatus} from '../data/enums/LabelStatus';
import {IPoint} from '../interfaces/IPoint';
import { sample } from 'lodash';
import {Settings} from '../settings/Settings';
import {ILine} from 'src/interfaces/ILine';

export type LabelCount = {
point: number;
line: number;
polygon: number;
rect: number;
}

export type PerLabelIdCountSummary = Record<string, LabelCount>;

export class LabelUtil {
public static createLabelName(name: string): LabelName {
Expand All @@ -16,19 +25,19 @@ export class LabelUtil {
}
}

public static createLabelRect(labelId: string, rect: IRect): LabelRect {
public static createLabelRect(labelId: string | null, rect: IRect, status: LabelStatus = LabelStatus.ACCEPTED): LabelRect {
return {
id: uuidv4(),
labelId,
rect,
isVisible: true,
isCreatedByAI: false,
status: LabelStatus.ACCEPTED,
status,
suggestedLabel: null
}
}

public static createLabelPolygon(labelId: string, vertices: IPoint[]): LabelPolygon {
public static createLabelPolygon(labelId: string | null, vertices: IPoint[]): LabelPolygon {
return {
id: uuidv4(),
labelId,
Expand All @@ -37,26 +46,60 @@ export class LabelUtil {
}
}

public static createLabelPoint(labelId: string, point: IPoint): LabelPoint {
public static createLabelPoint(labelId: string | null, point: IPoint, status: LabelStatus = LabelStatus.ACCEPTED): LabelPoint {
return {
id: uuidv4(),
labelId,
point,
isVisible: true,
isCreatedByAI: false,
status: LabelStatus.ACCEPTED,
status,
suggestedLabel: null
}
}

public static createLabelLine(labelId: string | null, line: ILine): LabelLine {
return {
id: uuidv4(),
labelId,
line,
isVisible: true
}
}

public static toggleAnnotationVisibility<AnnotationType extends Annotation>(annotation: AnnotationType): AnnotationType {
return {
...annotation,
isVisible: !annotation.isVisible
}
}

public static labelNamesIdsDiff(oldLabelNames: LabelName[], newLabelNames: LabelName[]): string[] {
public static calculatePerLabelIdCountSummary(labels: LabelName[], imagesData: ImageData[]): PerLabelIdCountSummary {
let labelCount = labels.reduce((acc: PerLabelIdCountSummary, label: LabelName) => {
acc[label.id] = { point: 0, line: 0, polygon: 0, rect: 0}
return acc;
}, {});
labelCount = imagesData.reduce((acc: PerLabelIdCountSummary, imageData: ImageData) => {
for (const labelRect of imageData.labelRects) {
if (labelRect.labelId !== null && labelRect.status === LabelStatus.ACCEPTED)
acc[labelRect.labelId].rect += 1
}
for (const labelPoint of imageData.labelPoints) {
if (labelPoint.labelId !== null && labelPoint.status === LabelStatus.ACCEPTED)
acc[labelPoint.labelId].point += 1
}
for (const labelLine of imageData.labelLines) {
if (labelLine.labelId !== null) acc[labelLine.labelId].line += 1
}
for (const labelPolygon of imageData.labelPolygons) {
if (labelPolygon.labelId !== null) acc[labelPolygon.labelId].polygon += 1
}
return acc;
}, labelCount)
return labelCount
}

public static calculateMissingLabelNamesIds(oldLabelNames: LabelName[], newLabelNames: LabelName[]): string[] {
return oldLabelNames.reduce((missingIds: string[], labelName: LabelName) => {
if (!find(newLabelNames, { 'id': labelName.id })) {
missingIds.push(labelName.id);
Expand Down
20 changes: 10 additions & 10 deletions src/utils/RectUtil.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {IRect} from "../interfaces/IRect";
import {IPoint} from "../interfaces/IPoint";
import {ISize} from "../interfaces/ISize";
import {RectAnchor} from "../data/RectAnchor";
import {NumberUtil} from "./NumberUtil";
import {Direction} from "../data/enums/Direction";
import {IRect} from '../interfaces/IRect';
import {IPoint} from '../interfaces/IPoint';
import {ISize} from '../interfaces/ISize';
import {RectAnchor} from '../data/RectAnchor';
import {NumberUtil} from './NumberUtil';
import {Direction} from '../data/enums/Direction';

export class RectUtil {
public static getRatio(rect: IRect): number {
Expand Down Expand Up @@ -61,7 +61,7 @@ export class RectUtil {
}
}
}

public static resizeRect(inputRect: IRect, rectAnchor: Direction, delta): IRect {
const rect: IRect = {...inputRect};
switch (rectAnchor) {
Expand Down Expand Up @@ -100,17 +100,17 @@ export class RectUtil {
rect.height += delta.y;
break;
}

if (rect.width < 0) {
rect.x = rect.x + rect.width;
rect.width = -rect.width;
}

if (rect.height < 0) {
rect.y = rect.y + rect.height;
rect.height = -rect.height;
}

return rect;
}

Expand Down
Loading