-
-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from SkalskiP/develop
1.5.0-alpha relese
- Loading branch information
Showing
82 changed files
with
1,744 additions
and
626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as posenet from '@tensorflow-models/posenet'; | ||
import {PoseNet} from "@tensorflow-models/posenet"; | ||
import {Pose} from "@tensorflow-models/posenet"; | ||
import {store} from "../index"; | ||
import {updatePoseDetectorStatus} from "../store/ai/actionCreators"; | ||
import {AIPoseDetectionActions} from "../logic/actions/AIPoseDetectionActions"; | ||
import {LabelType} from "../data/enums/LabelType"; | ||
import {LabelsSelector} from "../store/selectors/LabelsSelector"; | ||
import {updateActiveLabelType} from "../store/labels/actionCreators"; | ||
|
||
export class PoseDetector { | ||
private static model: PoseNet; | ||
|
||
public static loadModel(callback?: () => any) { | ||
posenet | ||
.load({ | ||
architecture: 'ResNet50', | ||
outputStride: 32, | ||
inputResolution: 257, | ||
quantBytes: 2 | ||
}) | ||
.then((model: PoseNet) => { | ||
PoseDetector.model = model; | ||
store.dispatch(updatePoseDetectorStatus(true)); | ||
store.dispatch(updateActiveLabelType(LabelType.POINT)); | ||
const activeLabelType: LabelType = LabelsSelector.getActiveLabelType(); | ||
activeLabelType === LabelType.POINT && AIPoseDetectionActions.detectPoseForActiveImage(); | ||
callback && callback(); | ||
}) | ||
.catch((error) => { | ||
// TODO | ||
throw new Error(error); | ||
}) | ||
} | ||
|
||
public static predict(image: HTMLImageElement, callback?: (predictions: Pose[]) => any) { | ||
if (!PoseDetector.model) return; | ||
|
||
PoseDetector.model | ||
.estimateMultiplePoses(image) | ||
.then((predictions: Pose[]) => { | ||
callback && callback(predictions) | ||
}) | ||
.catch((error) => { | ||
// TODO | ||
throw new Error(error); | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum AIModel { | ||
OBJECT_DETECTION = "OBJECT_DETECTION", | ||
POSE_DETECTION = "POSE_DETECTION" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
export enum PopupWindowType { | ||
LOAD_LABEL_NAMES = "LOAD_LABEL_NAMES", | ||
UPDATE_LABEL_NAMES = "UPDATE_LABEL_NAMES", | ||
SUGGEST_LABEL_NAMES = "SUGGEST_LABEL_NAMES", | ||
LOAD_IMAGES = "LOAD_IMAGES", | ||
LOAD_AI_MODEL = "LOAD_AI_MODEL", | ||
EXPORT_LABELS = "EXPORT_LABELS", | ||
INSERT_LABEL_NAMES = 'INSERT_LABEL_NAMES', | ||
EXIT_PROJECT = 'EXIT_PROJECT' | ||
EXIT_PROJECT = 'EXIT_PROJECT', | ||
LOADER = 'LOADER' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,54 @@ | ||
import {DetectedObject} from "@tensorflow-models/coco-ssd"; | ||
import {ImageData, LabelRect} from "../../store/labels/types"; | ||
import {LabelType} from "../../data/enums/LabelType"; | ||
import {LabelsSelector} from "../../store/selectors/LabelsSelector"; | ||
import uuidv1 from 'uuid/v1'; | ||
import {store} from "../../index"; | ||
import {updateImageDataById} from "../../store/labels/actionCreators"; | ||
import {ObjectDetector} from "../../ai/ObjectDetector"; | ||
import {ImageRepository} from "../imageRepository/ImageRepository"; | ||
import {LabelStatus} from "../../data/enums/LabelStatus"; | ||
import {AIObjectDetectionActions} from "./AIObjectDetectionActions"; | ||
import {AIPoseDetectionActions} from "./AIPoseDetectionActions"; | ||
import {ImageData} from "../../store/labels/types"; | ||
|
||
export class AIActions { | ||
public static detectRectsForActiveImage(): void { | ||
const activeImageData: ImageData = LabelsSelector.getActiveImageData(); | ||
AIActions.detectRects(activeImageData.id, ImageRepository.getById(activeImageData.id)) | ||
public static excludeRejectedLabelNames(suggestedLabels: string[], rejectedLabels: string[]): string[] { | ||
return suggestedLabels.reduce((acc: string[], label: string) => { | ||
if (!rejectedLabels.includes(label)) { | ||
acc.push(label) | ||
} | ||
return acc; | ||
}, []) | ||
} | ||
|
||
public static detectRects(imageId: string, image: HTMLImageElement): void { | ||
if (LabelsSelector.getImageDataById(imageId).isVisitedByObjectDetector) | ||
return; | ||
public static detect(imageId: string, image: HTMLImageElement): void { | ||
const activeLabelType: LabelType = LabelsSelector.getActiveLabelType(); | ||
|
||
ObjectDetector.predict(image, (predictions: DetectedObject[]) => { | ||
AIActions.savePredictions(imageId, predictions); | ||
}) | ||
switch (activeLabelType) { | ||
case LabelType.RECTANGLE: | ||
AIObjectDetectionActions.detectRects(imageId, image); | ||
break; | ||
case LabelType.POINT: | ||
AIPoseDetectionActions.detectPoses(imageId, image); | ||
break; | ||
} | ||
} | ||
|
||
public static savePredictions(imageId: string, predictions: DetectedObject[]) { | ||
const imageData: ImageData = LabelsSelector.getImageDataById(imageId); | ||
const predictedLabels: LabelRect[] = AIActions.mapPredictionsToRectLabels(predictions); | ||
const nextImageData: ImageData = { | ||
...imageData, | ||
labelRects: imageData.labelRects.concat(predictedLabels), | ||
isVisitedByObjectDetector: true | ||
}; | ||
store.dispatch(updateImageDataById(imageData.id, nextImageData)); | ||
public static rejectAllSuggestedLabels(imageData: ImageData) { | ||
const activeLabelType: LabelType = LabelsSelector.getActiveLabelType(); | ||
|
||
switch (activeLabelType) { | ||
case LabelType.RECTANGLE: | ||
AIObjectDetectionActions.rejectAllSuggestedRectLabels(imageData); | ||
break; | ||
case LabelType.POINT: | ||
AIPoseDetectionActions.rejectAllSuggestedPointLabels(imageData); | ||
break; | ||
} | ||
} | ||
|
||
public static mapPredictionsToRectLabels(predictions: DetectedObject[]): LabelRect[] { | ||
return predictions.map((prediction: DetectedObject) => { | ||
return { | ||
id: uuidv1(), | ||
labelIndex: null, | ||
rect: { | ||
x: prediction.bbox[0], | ||
y: prediction.bbox[1], | ||
width: prediction.bbox[2], | ||
height: prediction.bbox[3], | ||
}, | ||
isCreatedByAI: true, | ||
status: LabelStatus.UNDECIDED | ||
} | ||
}) | ||
public static acceptAllSuggestedLabels(imageData: ImageData) { | ||
const activeLabelType: LabelType = LabelsSelector.getActiveLabelType(); | ||
switch (activeLabelType) { | ||
case LabelType.RECTANGLE: | ||
AIObjectDetectionActions.acceptAllSuggestedRectLabels(imageData); | ||
break; | ||
case LabelType.POINT: | ||
AIPoseDetectionActions.acceptAllSuggestedPointLabels(imageData); | ||
break; | ||
} | ||
} | ||
} |
Oops, something went wrong.