Internal change

PiperOrigin-RevId: 499956657
This commit is contained in:
Sebastian Schmidt 2023-01-05 11:40:59 -08:00 committed by Copybara-Service
parent 81a46bb31a
commit 667fd81ddc
9 changed files with 75 additions and 56 deletions

View File

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

View File

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

View File

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

View File

@ -31,7 +31,8 @@ class TextEmbedderFake extends TextEmbedder implements MediapipeTasksFake {
graph: CalculatorGraphConfig|undefined;
attachListenerSpies: jasmine.Spy[] = [];
fakeWasmModule: SpyWasmModule;
protoListener: ((binaryProtos: Uint8Array) => void)|undefined;
protoListener:
((binaryProtos: Uint8Array, timestamp: number) => void)|undefined;
constructor() {
super(createSpyWasmModule(), /* glCanvas= */ null);
@ -120,7 +121,7 @@ describe('TextEmbedder', () => {
// Pass the test data to our listener
textEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(textEmbedder);
textEmbedder.protoListener!(resultProto.serializeBinary());
textEmbedder.protoListener!(resultProto.serializeBinary(), 1337);
});
// Invoke the text embedder
@ -149,7 +150,7 @@ describe('TextEmbedder', () => {
// Pass the test data to our listener
textEmbedder.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(textEmbedder);
textEmbedder.protoListener!(resultProto.serializeBinary());
textEmbedder.protoListener!(resultProto.serializeBinary(), 1337);
});
// 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.
// tslint:disable:jspb-use-builder-pattern
type ProtoListener = ((binaryProtos: Uint8Array[]) => void);
type ProtoListener = ((binaryProtos: Uint8Array[], timestamp: number) => void);
function createHandednesses(): Uint8Array[] {
const handsProto = new ClassificationList();
@ -254,11 +254,13 @@ describe('GestureRecognizer', () => {
// Pass the test data to our listener
gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(gestureRecognizer);
gestureRecognizer.listeners.get('hand_landmarks')!(createLandmarks());
gestureRecognizer.listeners.get('hand_landmarks')!
(createLandmarks(), 1337);
gestureRecognizer.listeners.get('world_hand_landmarks')!
(createWorldLandmarks());
gestureRecognizer.listeners.get('handedness')!(createHandednesses());
gestureRecognizer.listeners.get('hand_gestures')!(createGestures());
(createWorldLandmarks(), 1337);
gestureRecognizer.listeners.get('handedness')!
(createHandednesses(), 1337);
gestureRecognizer.listeners.get('hand_gestures')!(createGestures(), 1337);
});
// Invoke the gesture recognizer
@ -290,11 +292,13 @@ describe('GestureRecognizer', () => {
it('clears results between invoations', async () => {
// Pass the test data to our listener
gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => {
gestureRecognizer.listeners.get('hand_landmarks')!(createLandmarks());
gestureRecognizer.listeners.get('hand_landmarks')!
(createLandmarks(), 1337);
gestureRecognizer.listeners.get('world_hand_landmarks')!
(createWorldLandmarks());
gestureRecognizer.listeners.get('handedness')!(createHandednesses());
gestureRecognizer.listeners.get('hand_gestures')!(createGestures());
(createWorldLandmarks(), 1337);
gestureRecognizer.listeners.get('handedness')!
(createHandednesses(), 1337);
gestureRecognizer.listeners.get('hand_gestures')!(createGestures(), 1337);
});
// Invoke the gesture recognizer twice
@ -310,11 +314,13 @@ describe('GestureRecognizer', () => {
// Pass the test data to our listener
gestureRecognizer.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(gestureRecognizer);
gestureRecognizer.listeners.get('hand_landmarks')!(createLandmarks());
gestureRecognizer.listeners.get('hand_landmarks')!
(createLandmarks(), 1337);
gestureRecognizer.listeners.get('world_hand_landmarks')!
(createWorldLandmarks());
gestureRecognizer.listeners.get('handedness')!(createHandednesses());
gestureRecognizer.listeners.get('hand_gestures')!([]);
(createWorldLandmarks(), 1337);
gestureRecognizer.listeners.get('handedness')!
(createHandednesses(), 1337);
gestureRecognizer.listeners.get('hand_gestures')!([], 1337);
});
// 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.
// tslint:disable:jspb-use-builder-pattern
type ProtoListener = ((binaryProtos: Uint8Array[]) => void);
type ProtoListener = ((binaryProtos: Uint8Array[], timestamp: number) => void);
function createHandednesses(): Uint8Array[] {
const handsProto = new ClassificationList();
@ -206,10 +206,10 @@ describe('HandLandmarker', () => {
// Pass the test data to our listener
handLandmarker.fakeWasmModule._waitUntilIdle.and.callFake(() => {
verifyListenersRegistered(handLandmarker);
handLandmarker.listeners.get('hand_landmarks')!(createLandmarks());
handLandmarker.listeners.get('hand_landmarks')!(createLandmarks(), 1337);
handLandmarker.listeners.get('world_hand_landmarks')!
(createWorldLandmarks());
handLandmarker.listeners.get('handedness')!(createHandednesses());
(createWorldLandmarks(), 1337);
handLandmarker.listeners.get('handedness')!(createHandednesses(), 1337);
});
// Invoke the hand landmarker
@ -235,10 +235,10 @@ describe('HandLandmarker', () => {
it('clears results between invoations', async () => {
// Pass the test data to our listener
handLandmarker.fakeWasmModule._waitUntilIdle.and.callFake(() => {
handLandmarker.listeners.get('hand_landmarks')!(createLandmarks());
handLandmarker.listeners.get('hand_landmarks')!(createLandmarks(), 1337);
handLandmarker.listeners.get('world_hand_landmarks')!
(createWorldLandmarks());
handLandmarker.listeners.get('handedness')!(createHandednesses());
(createWorldLandmarks(), 1337);
handLandmarker.listeners.get('handedness')!(createHandednesses(), 1337);
});
// Invoke the hand landmarker twice

View File

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

View File

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