Finetuned-MobilVIT / 2Inference.py
Nekshay's picture
Create 2Inference.py
2a4cd0e
raw
history blame contribute delete
No virus
1.44 kB
async function cropImage(imageUri, topLeftCoords, bottomRightCoords) {
const { uri } = await ImageManipulator.manipulateAsync(
imageUri,
[
{
crop: {
originX: topLeftCoords.x,
originY: topLeftCoords.y,
width: bottomRightCoords.x - topLeftCoords.x,
height: bottomRightCoords.y - topLeftCoords.y,
},
},
],
{ compress: 1, format: ImageManipulator.SaveFormat.JPEG }
);
return uri;
}
export class ModelService {
// ... (existing code)
async classifyCroppedImages(image: ImageManipulator.ImageResult, topLeftCoords1, bottomRightCoords1, topLeftCoords2, bottomRightCoords2): Promise<IModelPredictionResponse[]> {
const croppedImageUri1 = await cropImage(image.uri, topLeftCoords1, bottomRightCoords1);
const croppedImageUri2 = await cropImage(image.uri, topLeftCoords2, bottomRightCoords2);
const croppedImage1: ImageManipulator.ImageResult = await ImageManipulator.manipulateAsync(
croppedImageUri1,
[],
{ base64: true }
);
const croppedImage2: ImageManipulator.ImageResult = await ImageManipulator.manipulateAsync(
croppedImageUri2,
[],
{ base64: true }
);
const [predictionResponse1, predictionResponse2] = await Promise.all([
this.classifyImage(croppedImage1),
this.classifyImage(croppedImage2),
]);
return [predictionResponse1, predictionResponse2];
}
}