-
-
Notifications
You must be signed in to change notification settings - Fork 526
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 #62 from SkalskiP/develop
1.4.0-alpha relese merge
- Loading branch information
Showing
82 changed files
with
1,025 additions
and
391 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.
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
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
@import './settings/_Settings'; | ||
|
||
//.App { | ||
// height: 100vh; | ||
// width: 100vw; | ||
// margin: 0; | ||
// padding: 0; | ||
//} | ||
.App { | ||
--leading-color: #{$secondaryColor}; | ||
--hue-value: 172deg; | ||
} | ||
|
||
.App.AI { | ||
--leading-color: #{$primaryColor}; | ||
--hue-value: 120deg; | ||
} |
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,12 @@ | ||
const Environment = require('jest-environment-jsdom'); | ||
|
||
/** | ||
* A custom environment to set the TextEncoder that is required by TensorFlow.js. | ||
*/ | ||
module.exports = class CustomTestEnvironment extends Environment { | ||
async setup() { | ||
await super.setup(); | ||
const { TextEncoder } = require('util'); | ||
this.global.TextEncoder = TextEncoder; | ||
} | ||
} |
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,39 @@ | ||
import * as cocoSsd from '@tensorflow-models/coco-ssd'; | ||
import {ObjectDetection} from "@tensorflow-models/coco-ssd"; | ||
import {DetectedObject} from "@tensorflow-models/coco-ssd"; | ||
import {store} from "../index"; | ||
import {updateObjectDetectorStatus} from "../store/ai/actionCreators"; | ||
import {AIActions} from "../logic/actions/AIActions"; | ||
|
||
export class ObjectDetector { | ||
private static model: ObjectDetection; | ||
|
||
public static loadModel(callback?: () => any) { | ||
cocoSsd | ||
.load() | ||
.then((model: ObjectDetection) => { | ||
ObjectDetector.model = model; | ||
store.dispatch(updateObjectDetectorStatus(true)); | ||
AIActions.detectRectsForActiveImage(); | ||
callback && callback(); | ||
}) | ||
.catch((error) => { | ||
// TODO | ||
throw new Error(error); | ||
}) | ||
} | ||
|
||
public static predict(image: HTMLImageElement, callback?: (predictions: DetectedObject[]) => any) { | ||
if (!ObjectDetector.model) return; | ||
|
||
ObjectDetector.model | ||
.detect(image) | ||
.then((predictions: DetectedObject[]) => { | ||
callback && callback(predictions) | ||
}) | ||
.catch((error) => { | ||
// TODO | ||
throw new Error(error); | ||
}) | ||
} | ||
} |
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,5 @@ | ||
export enum LabelStatus { | ||
ACCEPTED = "ACCEPTED", | ||
REJECTED = "REJECTED", | ||
UNDECIDED = "UNDECIDED" | ||
} |
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,53 @@ | ||
import {DetectedObject} from "@tensorflow-models/coco-ssd"; | ||
import {ImageData, LabelRect} from "../../store/labels/types"; | ||
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"; | ||
|
||
export class AIActions { | ||
public static detectRectsForActiveImage(): void { | ||
const activeImageData: ImageData = LabelsSelector.getActiveImageData(); | ||
AIActions.detectRects(activeImageData.id, ImageRepository.getById(activeImageData.id)) | ||
} | ||
|
||
public static detectRects(imageId: string, image: HTMLImageElement): void { | ||
if (LabelsSelector.getImageDataById(imageId).isVisitedByObjectDetector) | ||
return; | ||
|
||
ObjectDetector.predict(image, (predictions: DetectedObject[]) => { | ||
AIActions.savePredictions(imageId, predictions); | ||
}) | ||
} | ||
|
||
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 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 | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.