Has anyone tried to create a web app for a segmentation problem?
I have successfully used: https://github.com/render-examples/fastai-v3 to do my own image classification problems.
But, with segmentation rather than use, per the above:
prediction = learn.predict(img)
return JSONResponse({'result': str(prediction)})
Which works and gives me i.e.:
Result = (ImageSegment (1, 256, 256), tensor([[[1, 1, 1, ..., 0, 0, 0], [1, 1, 1, ..., 0, 0, 0], [1, 1, 1, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]]]), tensor([[[8.5772e-02, 8.4360e-02, 1.0073e-01, ..., 9.9956e-01, 9.9786e-01, 9.9232e-01], [1.1104e-01, 9.4421e-02, 1.2525e-01, ..., 9.9988e-01, 9.9905e-01, 9.9127e-01], [1.5099e-01, 1.4895e-01, 1.8742e-01, ..., 9.9993e-01, 9.9962e-01, 9.9481e-01], ..., [8.7420e-01, 9.2307e-01, 8.3781e-01, ..., 9.8641e-01, 9.8990e-01, 9.6547e-01], [9.1475e-01, 9.4999e-01, 9.1047e-01, ..., 9.8308e-01, 9.8245e-01, 9.4360e-01], [8.9638e-01, 9.1444e-01, 8.8966e-01, ..., 9.6006e-01, 9.3871e-01, 8.6142e-01]], [[9.1423e-01, 9.1564e-01, 8.9927e-01, ..., 4.4379e-04, 2.1372e-03, 7.6819e-03], [8.8896e-01, 9.0558e-01, 8.7475e-01, ..., 1.1997e-04, 9.5195e-04, 8.7291e-03], [8.4901e-01, 8.5105e-01, 8.1258e-01, ..., 6.8235e-05, 3.7505e-04, 5.1882e-03], ..., [1.2580e-01, 7.6933e-02, 1.6219e-01, ..., 1.3586e-02, 1.0098e-02, 3.4532e-02], [8.5250e-02, 5.0013e-02, 8.9535e-02, ..., 1.6916e-02, 1.7554e-02, 5.6399e-02], [1.0362e-01, 8.5556e-02, 1.1034e-01, ..., 3.9943e-02, 6.1291e-02, 1.3858e-01]]]))
I would rather show the segmented image. But, since the segmented image is an overlay when you run:
img.show(y=learn.predict(img)[0])
I would rather show just the segments (as a second image that then shows underneath the image that is uploaded). The uploaded image shows per the above Github repository. So, I just wrote the following, which works just fine and shows what I want in my jupyter notebook:
prediction = learn.predict(img)
think_np = np.array(prediction[1])
think_np.shape = (256,256)
think_np = think_np.astype(int)
think_np[think_np > 0] = 255
think_im = PilImage.fromarray((think_np).astype('uint8'), mode='L')
Granted my HTML, CSS, JSON being weak is a big understatement. But, I am trying to get āthink_imā to show as āresultā after hitting the analyze button, rather than (in replace of) showing str(prediction).
So, I replaced:
return JSONResponse({'result': str(prediction)})
With:
return JSONResponse({'result': think_im})
And then I didnāt change anything in the client.js (let alone yet the HMTL and CSS). But even before looking into those, just on the server.py getting the following error:
TypeError: Object of type 'Image' is not JSON serializable
I have been trying to research this, but not getting off the starting blocks. Appreciate any pointers.