Merge branch 'master' into ios-text-classifier

This commit is contained in:
Prianka Liz Kariat 2023-01-06 15:53:13 +05:30
commit 683ca0cf4b
9 changed files with 75 additions and 56 deletions

View File

@ -34,7 +34,8 @@ class AudioClassifierFake extends AudioClassifier implements
attachListenerSpies: jasmine.Spy[] = []; attachListenerSpies: jasmine.Spy[] = [];
graph: CalculatorGraphConfig|undefined; graph: CalculatorGraphConfig|undefined;
private protoVectorListener: ((binaryProtos: Uint8Array[]) => void)|undefined; private protoVectorListener:
((binaryProtos: Uint8Array[], timestamp: number) => void)|undefined;
private resultProtoVector: ClassificationResult[] = []; private resultProtoVector: ClassificationResult[] = [];
constructor() { constructor() {
@ -59,8 +60,10 @@ class AudioClassifierFake extends AudioClassifier implements
}); });
spyOn(this.graphRunner, 'finishProcessing').and.callFake(() => { spyOn(this.graphRunner, 'finishProcessing').and.callFake(() => {
if (!this.protoVectorListener) return; if (!this.protoVectorListener) return;
this.protoVectorListener(this.resultProtoVector.map( this.protoVectorListener(
classificationResult => classificationResult.serializeBinary())); this.resultProtoVector.map(
classificationResult => classificationResult.serializeBinary()),
1337);
}); });
spyOn(this.graphRunner, 'setGraph').and.callFake(binaryGraph => { spyOn(this.graphRunner, 'setGraph').and.callFake(binaryGraph => {
this.graph = CalculatorGraphConfig.deserializeBinary(binaryGraph); this.graph = CalculatorGraphConfig.deserializeBinary(binaryGraph);
@ -138,12 +141,12 @@ describe('AudioClassifier', () => {
classifcations.setHeadIndex(1); classifcations.setHeadIndex(1);
classifcations.setHeadName('headName'); classifcations.setHeadName('headName');
let classificationList = new ClassificationList(); let classificationList = new ClassificationList();
let clasification = new Classification(); let classification = new Classification();
clasification.setIndex(1); classification.setIndex(1);
clasification.setScore(0.2); classification.setScore(0.2);
clasification.setDisplayName('displayName'); classification.setDisplayName('displayName');
clasification.setLabel('categoryName'); classification.setLabel('categoryName');
classificationList.addClassification(clasification); classificationList.addClassification(classification);
classifcations.setClassificationList(classificationList); classifcations.setClassificationList(classificationList);
classificationResult.addClassifications(classifcations); classificationResult.addClassifications(classifcations);
resultProtoVector.push(classificationResult); resultProtoVector.push(classificationResult);
@ -152,10 +155,10 @@ describe('AudioClassifier', () => {
classificationResult.setTimestampMs(1); classificationResult.setTimestampMs(1);
classifcations = new Classifications(); classifcations = new Classifications();
classificationList = new ClassificationList(); classificationList = new ClassificationList();
clasification = new Classification(); classification = new Classification();
clasification.setIndex(2); classification.setIndex(2);
clasification.setScore(0.3); classification.setScore(0.3);
classificationList.addClassification(clasification); classificationList.addClassification(classification);
classifcations.setClassificationList(classificationList); classifcations.setClassificationList(classificationList);
classificationResult.addClassifications(classifcations); classificationResult.addClassifications(classifcations);
resultProtoVector.push(classificationResult); resultProtoVector.push(classificationResult);
@ -191,8 +194,8 @@ describe('AudioClassifier', () => {
const classificationResult = new ClassificationResult(); const classificationResult = new ClassificationResult();
const classifcations = new Classifications(); const classifcations = new Classifications();
const classificationList = new ClassificationList(); const classificationList = new ClassificationList();
const clasification = new Classification(); const classification = new Classification();
classificationList.addClassification(clasification); classificationList.addClassification(classification);
classifcations.setClassificationList(classificationList); classifcations.setClassificationList(classificationList);
classificationResult.addClassifications(classifcations); classificationResult.addClassifications(classifcations);

View File

@ -34,8 +34,10 @@ class AudioEmbedderFake extends AudioEmbedder implements MediapipeTasksFake {
attachListenerSpies: jasmine.Spy[] = []; attachListenerSpies: jasmine.Spy[] = [];
fakeWasmModule: SpyWasmModule; fakeWasmModule: SpyWasmModule;
protoListener: ((binaryProto: Uint8Array) => void)|undefined; protoListener:
protoVectorListener: ((binaryProtos: Uint8Array[]) => void)|undefined; ((binaryProto: Uint8Array, timestamp: number) => void)|undefined;
protoVectorListener:
((binaryProtos: Uint8Array[], timestamp: number) => void)|undefined;
constructor() { constructor() {
super(createSpyWasmModule(), /* glCanvas= */ null); super(createSpyWasmModule(), /* glCanvas= */ null);
@ -163,7 +165,7 @@ describe('AudioEmbedder', () => {
audioEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => { audioEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(audioEmbedder); verifyListenersRegistered(audioEmbedder);
// Pass the test data to our listener // Pass the test data to our listener
audioEmbedder.protoListener!(resultProto.serializeBinary()); audioEmbedder.protoListener!(resultProto.serializeBinary(), 1337);
}); });
// Invoke the audio embedder // Invoke the audio embedder
@ -175,7 +177,8 @@ describe('AudioEmbedder', () => {
audioEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => { audioEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(audioEmbedder); verifyListenersRegistered(audioEmbedder);
// Pass the test data to our listener // Pass the test data to our listener
audioEmbedder.protoVectorListener!([resultProto.serializeBinary()]); audioEmbedder.protoVectorListener!
([resultProto.serializeBinary()], 1337);
}); });
// Invoke the audio embedder // Invoke the audio embedder

View File

@ -32,7 +32,8 @@ class TextClassifierFake extends TextClassifier implements MediapipeTasksFake {
attachListenerSpies: jasmine.Spy[] = []; attachListenerSpies: jasmine.Spy[] = [];
graph: CalculatorGraphConfig|undefined; graph: CalculatorGraphConfig|undefined;
fakeWasmModule: SpyWasmModule; fakeWasmModule: SpyWasmModule;
protoListener: ((binaryProto: Uint8Array) => void)|undefined; protoListener:
((binaryProto: Uint8Array, timestamp: number) => void)|undefined;
constructor() { constructor() {
super(createSpyWasmModule(), /* glCanvas= */ null); super(createSpyWasmModule(), /* glCanvas= */ null);
@ -118,19 +119,20 @@ describe('TextClassifier', () => {
classifcations.setHeadIndex(1); classifcations.setHeadIndex(1);
classifcations.setHeadName('headName'); classifcations.setHeadName('headName');
const classificationList = new ClassificationList(); const classificationList = new ClassificationList();
const clasification = new Classification(); const classification = new Classification();
clasification.setIndex(1); classification.setIndex(1);
clasification.setScore(0.2); classification.setScore(0.2);
clasification.setDisplayName('displayName'); classification.setDisplayName('displayName');
clasification.setLabel('categoryName'); classification.setLabel('categoryName');
classificationList.addClassification(clasification); classificationList.addClassification(classification);
classifcations.setClassificationList(classificationList); classifcations.setClassificationList(classificationList);
classificationResult.addClassifications(classifcations); classificationResult.addClassifications(classifcations);
// Pass the test data to our listener // Pass the test data to our listener
textClassifier.fakeWasmModule._waitUntilIdle.and.callFake(() => { textClassifier.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(textClassifier); verifyListenersRegistered(textClassifier);
textClassifier.protoListener!(classificationResult.serializeBinary()); textClassifier.protoListener!
(classificationResult.serializeBinary(), 1337);
}); });
// Invoke the text classifier // Invoke the text classifier

View File

@ -31,7 +31,8 @@ class TextEmbedderFake extends TextEmbedder implements MediapipeTasksFake {
graph: CalculatorGraphConfig|undefined; graph: CalculatorGraphConfig|undefined;
attachListenerSpies: jasmine.Spy[] = []; attachListenerSpies: jasmine.Spy[] = [];
fakeWasmModule: SpyWasmModule; fakeWasmModule: SpyWasmModule;
protoListener: ((binaryProtos: Uint8Array) => void)|undefined; protoListener:
((binaryProtos: Uint8Array, timestamp: number) => void)|undefined;
constructor() { constructor() {
super(createSpyWasmModule(), /* glCanvas= */ null); super(createSpyWasmModule(), /* glCanvas= */ null);
@ -120,7 +121,7 @@ describe('TextEmbedder', () => {
// Pass the test data to our listener // Pass the test data to our listener
textEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => { textEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(textEmbedder); verifyListenersRegistered(textEmbedder);
textEmbedder.protoListener!(resultProto.serializeBinary()); textEmbedder.protoListener!(resultProto.serializeBinary(), 1337);
}); });
// Invoke the text embedder // Invoke the text embedder
@ -149,7 +150,7 @@ describe('TextEmbedder', () => {
// Pass the test data to our listener // Pass the test data to our listener
textEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => { textEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(textEmbedder); verifyListenersRegistered(textEmbedder);
textEmbedder.protoListener!(resultProto.serializeBinary()); textEmbedder.protoListener!(resultProto.serializeBinary(), 1337);
}); });
// Invoke the text embedder // Invoke the text embedder

View File

@ -26,7 +26,7 @@ import {GestureRecognizer, GestureRecognizerOptions} from './gesture_recognizer'
// The OSS JS API does not support the builder pattern. // The OSS JS API does not support the builder pattern.
// tslint:disable:jspb-use-builder-pattern // tslint:disable:jspb-use-builder-pattern
type ProtoListener = ((binaryProtos: Uint8Array[]) => void); type ProtoListener = ((binaryProtos: Uint8Array[], timestamp: number) => void);
function createHandednesses(): Uint8Array[] { function createHandednesses(): Uint8Array[] {
const handsProto = new ClassificationList(); const handsProto = new ClassificationList();
@ -254,11 +254,13 @@ describe('GestureRecognizer', () => {
// Pass the test data to our listener // Pass the test data to our listener
gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => { gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(gestureRecognizer); verifyListenersRegistered(gestureRecognizer);
gestureRecognizer.listeners.get('hand_landmarks')!(createLandmarks()); gestureRecognizer.listeners.get('hand_landmarks')!
(createLandmarks(), 1337);
gestureRecognizer.listeners.get('world_hand_landmarks')! gestureRecognizer.listeners.get('world_hand_landmarks')!
(createWorldLandmarks()); (createWorldLandmarks(), 1337);
gestureRecognizer.listeners.get('handedness')!(createHandednesses()); gestureRecognizer.listeners.get('handedness')!
gestureRecognizer.listeners.get('hand_gestures')!(createGestures()); (createHandednesses(), 1337);
gestureRecognizer.listeners.get('hand_gestures')!(createGestures(), 1337);
}); });
// Invoke the gesture recognizer // Invoke the gesture recognizer
@ -290,11 +292,13 @@ describe('GestureRecognizer', () => {
it('clears results between invoations', async () => { it('clears results between invoations', async () => {
// Pass the test data to our listener // Pass the test data to our listener
gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => { gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => {
gestureRecognizer.listeners.get('hand_landmarks')!(createLandmarks()); gestureRecognizer.listeners.get('hand_landmarks')!
(createLandmarks(), 1337);
gestureRecognizer.listeners.get('world_hand_landmarks')! gestureRecognizer.listeners.get('world_hand_landmarks')!
(createWorldLandmarks()); (createWorldLandmarks(), 1337);
gestureRecognizer.listeners.get('handedness')!(createHandednesses()); gestureRecognizer.listeners.get('handedness')!
gestureRecognizer.listeners.get('hand_gestures')!(createGestures()); (createHandednesses(), 1337);
gestureRecognizer.listeners.get('hand_gestures')!(createGestures(), 1337);
}); });
// Invoke the gesture recognizer twice // Invoke the gesture recognizer twice
@ -310,11 +314,13 @@ describe('GestureRecognizer', () => {
// Pass the test data to our listener // Pass the test data to our listener
gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => { gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(gestureRecognizer); verifyListenersRegistered(gestureRecognizer);
gestureRecognizer.listeners.get('hand_landmarks')!(createLandmarks()); gestureRecognizer.listeners.get('hand_landmarks')!
(createLandmarks(), 1337);
gestureRecognizer.listeners.get('world_hand_landmarks')! gestureRecognizer.listeners.get('world_hand_landmarks')!
(createWorldLandmarks()); (createWorldLandmarks(), 1337);
gestureRecognizer.listeners.get('handedness')!(createHandednesses()); gestureRecognizer.listeners.get('handedness')!
gestureRecognizer.listeners.get('hand_gestures')!([]); (createHandednesses(), 1337);
gestureRecognizer.listeners.get('hand_gestures')!([], 1337);
}); });
// Invoke the gesture recognizer // Invoke the gesture recognizer

View File

@ -27,7 +27,7 @@ import {HandLandmarkerOptions} from './hand_landmarker_options';
// The OSS JS API does not support the builder pattern. // The OSS JS API does not support the builder pattern.
// tslint:disable:jspb-use-builder-pattern // tslint:disable:jspb-use-builder-pattern
type ProtoListener = ((binaryProtos: Uint8Array[]) => void); type ProtoListener = ((binaryProtos: Uint8Array[], timestamp: number) => void);
function createHandednesses(): Uint8Array[] { function createHandednesses(): Uint8Array[] {
const handsProto = new ClassificationList(); const handsProto = new ClassificationList();
@ -206,10 +206,10 @@ describe('HandLandmarker', () => {
// Pass the test data to our listener // Pass the test data to our listener
handLandmarker.fakeWasmModule._waitUntilIdle.and.callFake(() => { handLandmarker.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(handLandmarker); verifyListenersRegistered(handLandmarker);
handLandmarker.listeners.get('hand_landmarks')!(createLandmarks()); handLandmarker.listeners.get('hand_landmarks')!(createLandmarks(), 1337);
handLandmarker.listeners.get('world_hand_landmarks')! handLandmarker.listeners.get('world_hand_landmarks')!
(createWorldLandmarks()); (createWorldLandmarks(), 1337);
handLandmarker.listeners.get('handedness')!(createHandednesses()); handLandmarker.listeners.get('handedness')!(createHandednesses(), 1337);
}); });
// Invoke the hand landmarker // Invoke the hand landmarker
@ -235,10 +235,10 @@ describe('HandLandmarker', () => {
it('clears results between invoations', async () => { it('clears results between invoations', async () => {
// Pass the test data to our listener // Pass the test data to our listener
handLandmarker.fakeWasmModule._waitUntilIdle.and.callFake(() => { handLandmarker.fakeWasmModule._waitUntilIdle.and.callFake(() => {
handLandmarker.listeners.get('hand_landmarks')!(createLandmarks()); handLandmarker.listeners.get('hand_landmarks')!(createLandmarks(), 1337);
handLandmarker.listeners.get('world_hand_landmarks')! handLandmarker.listeners.get('world_hand_landmarks')!
(createWorldLandmarks()); (createWorldLandmarks(), 1337);
handLandmarker.listeners.get('handedness')!(createHandednesses()); handLandmarker.listeners.get('handedness')!(createHandednesses(), 1337);
}); });
// Invoke the hand landmarker twice // Invoke the hand landmarker twice

View File

@ -35,7 +35,8 @@ class ImageClassifierFake extends ImageClassifier implements
graph: CalculatorGraphConfig|undefined; graph: CalculatorGraphConfig|undefined;
fakeWasmModule: SpyWasmModule; fakeWasmModule: SpyWasmModule;
protoListener: ((binaryProto: Uint8Array) => void)|undefined; protoListener:
((binaryProto: Uint8Array, timestamp: number) => void)|undefined;
constructor() { constructor() {
super(createSpyWasmModule(), /* glCanvas= */ null); super(createSpyWasmModule(), /* glCanvas= */ null);
@ -128,7 +129,8 @@ describe('ImageClassifier', () => {
// Pass the test data to our listener // Pass the test data to our listener
imageClassifier.fakeWasmModule._waitUntilIdle.and.callFake(() => { imageClassifier.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(imageClassifier); verifyListenersRegistered(imageClassifier);
imageClassifier.protoListener!(classificationResult.serializeBinary()); imageClassifier.protoListener!
(classificationResult.serializeBinary(), 1337);
}); });
// Invoke the image classifier // Invoke the image classifier

View File

@ -31,7 +31,8 @@ class ImageEmbedderFake extends ImageEmbedder implements MediapipeTasksFake {
graph: CalculatorGraphConfig|undefined; graph: CalculatorGraphConfig|undefined;
attachListenerSpies: jasmine.Spy[] = []; attachListenerSpies: jasmine.Spy[] = [];
fakeWasmModule: SpyWasmModule; fakeWasmModule: SpyWasmModule;
protoListener: ((binaryProtos: Uint8Array) => void)|undefined; protoListener:
((binaryProtos: Uint8Array, timestamp: number) => void)|undefined;
constructor() { constructor() {
super(createSpyWasmModule(), /* glCanvas= */ null); super(createSpyWasmModule(), /* glCanvas= */ null);
@ -125,7 +126,7 @@ describe('ImageEmbedder', () => {
// Pass the test data to our listener // Pass the test data to our listener
imageEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => { imageEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(imageEmbedder); verifyListenersRegistered(imageEmbedder);
imageEmbedder.protoListener!(resultProto.serializeBinary()); imageEmbedder.protoListener!(resultProto.serializeBinary(), 1337);
}); });
}); });

View File

@ -35,7 +35,8 @@ class ObjectDetectorFake extends ObjectDetector implements MediapipeTasksFake {
graph: CalculatorGraphConfig|undefined; graph: CalculatorGraphConfig|undefined;
fakeWasmModule: SpyWasmModule; fakeWasmModule: SpyWasmModule;
protoListener: ((binaryProtos: Uint8Array[]) => void)|undefined; protoListener:
((binaryProtos: Uint8Array[], timestamp: number) => void)|undefined;
constructor() { constructor() {
super(createSpyWasmModule(), /* glCanvas= */ null); super(createSpyWasmModule(), /* glCanvas= */ null);
@ -200,7 +201,7 @@ describe('ObjectDetector', () => {
// Pass the test data to our listener // Pass the test data to our listener
objectDetector.fakeWasmModule._waitUntilIdle.and.callFake(() => { objectDetector.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(objectDetector); verifyListenersRegistered(objectDetector);
objectDetector.protoListener!(detectionProtos); objectDetector.protoListener!(detectionProtos, 1337);
}); });
// Invoke the object detector // Invoke the object detector