Nekshay commited on
Commit
2a4cd0e
1 Parent(s): d9f5705

Create 2Inference.py

Browse files
Files changed (1) hide show
  1. 2Inference.py +45 -0
2Inference.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function cropImage(imageUri, topLeftCoords, bottomRightCoords) {
2
+ const { uri } = await ImageManipulator.manipulateAsync(
3
+ imageUri,
4
+ [
5
+ {
6
+ crop: {
7
+ originX: topLeftCoords.x,
8
+ originY: topLeftCoords.y,
9
+ width: bottomRightCoords.x - topLeftCoords.x,
10
+ height: bottomRightCoords.y - topLeftCoords.y,
11
+ },
12
+ },
13
+ ],
14
+ { compress: 1, format: ImageManipulator.SaveFormat.JPEG }
15
+ );
16
+ return uri;
17
+ }
18
+
19
+ export class ModelService {
20
+ // ... (existing code)
21
+
22
+ async classifyCroppedImages(image: ImageManipulator.ImageResult, topLeftCoords1, bottomRightCoords1, topLeftCoords2, bottomRightCoords2): Promise<IModelPredictionResponse[]> {
23
+ const croppedImageUri1 = await cropImage(image.uri, topLeftCoords1, bottomRightCoords1);
24
+ const croppedImageUri2 = await cropImage(image.uri, topLeftCoords2, bottomRightCoords2);
25
+
26
+ const croppedImage1: ImageManipulator.ImageResult = await ImageManipulator.manipulateAsync(
27
+ croppedImageUri1,
28
+ [],
29
+ { base64: true }
30
+ );
31
+
32
+ const croppedImage2: ImageManipulator.ImageResult = await ImageManipulator.manipulateAsync(
33
+ croppedImageUri2,
34
+ [],
35
+ { base64: true }
36
+ );
37
+
38
+ const [predictionResponse1, predictionResponse2] = await Promise.all([
39
+ this.classifyImage(croppedImage1),
40
+ this.classifyImage(croppedImage2),
41
+ ]);
42
+
43
+ return [predictionResponse1, predictionResponse2];
44
+ }
45
+ }