Hi, I am new to pytorch, I’m doing it on a OCR project, it should works on mobile platform. I’m having some difficult to use it. can anyone help please !!
[Question]:
1.I wanna know how to use my CTPN model detect the regions from giving picture, whether my code is correct ?
2. how to use output data, every thing is Tensor, how to found the region result from those Tensor result ?
3. A further question about this, I suppose the predict result of the RCNN detection is a tuple array that included some float array or tensor inside. so, how to convert those float data to a text character ?
[My Steps]:
- checked out a CTPN open source project and trained a model on my machine with Nvidia 3090 video card. ( there is a small set of labels and images inside of the project.)
- I converted the checkpoint file to a mobile optimized format, and I have successful loaded this model file on my Android phone.
- I picked up a picture from training set and pushed it into my android phone.
Below is the code : (java)
// load picture file
Bitmap bmp = BitmapFactory.decodeFile(picturePath.getAbsolutePath());
// convert picture to a tensor object.
final Tensor inputTensor = TensorImageUtils.bitmapToFloat32Tensor(bmp, TensorImageUtils.TORCHVISION_NORM_MEAN_RGB, TensorImageUtils.TORCHVISION_NORM_STD_RGB);
// load CTPN model file.
Module mDetector=LiteModuleLoader.load(Utils.assetFilePath(this,“ctpn_v3_mobile_ep27.ptl”));
// detect the label regions.
IValue detValue = mDetector.forward(IValue.from(inputTensor));
// output data is a tuple.
IValue[] tuple = detValue.toTuple();
for (int i = 0;i < tuple.length; i++) {
IValue val = tuple[i];
Tensor tens = val.toTensor();
float[] data = tens.getDataAsFloatArray();
//////////////////////////////// then, how to use the result data ???
}