Closed mighty98 closed 5 months ago
Hi @mighty98, the swin transformer backbone is brought from Swin Github Repo. Please refer to the original repository.
If you are trying to run the inference code only to generate mask, then try disable pretrained option. pretrained option link
Model:
name: "InSPyReNet_SwinB"
depth: 64
pretrained: True --> change this into False
base_size: [384, 384]
threshold: 512
Also, you can try using our python API & command line tool transparent-background
which is identical to this work but with more user friendly interface.
If you are trying to train on your own, then please feel free to add a comment for more help. I'll help you with this problem in that case.
Thanks.
@plemeri Thank you so much for the reply. I loved transparent-background but over there I see we have to load the state each time i want to infer. It is not working when i load the model once and export the model to infer n times. Not sure if what i told makes sense without code. But will you be able to help me with it..
Im a newbie on ML and so forgive my dumbness
I think in your case you need to use our tool as a Python API, not as a command line tool. Using our tool as a command line tool, a trained checkpoint (state) should be loaded each time. On the other hand, Python API does not load the checkpoint each time you infer the sample. Here are sample code for Python API.
import cv2
import numpy as np
from PIL import Image
from transparent_background import Remover
remover = Remover()
img = Image.open('samples/aeroplane.jpg').convert('RGB') # read image
out = remover.process(img)
out.save('output.png') # save result
In this script, remover.process
function can be called without loading checkpoint each time.
For more usage, please refer to Python API document in ReadMe file.
Please leave more comments if you need more help.
@plemeri Maybe im wrong but if you see the above code we are calling Remover() each time we call this api and at this point the init() function of Remover class is loading the weights. What i instead tried is creating a Remover() class instance once and export it and try call 'process()' of this exported instance. But on doing so it doesnt work.
Just don't call remover = Remover()
more than once, and call remover.process(img)
multiple times which works well.
Here is a simple example using for loop.
import os
import cv2
import numpy as np
from PIL import Image
from transparent_background import Remover
remover = Remover()
imgs = os.listdir('directory/to/images')
for img_file in imgs:
img = Image.open(img_file).convert('RGB') # read image
out = remover.process(img)
out.save(img_file) # save result
In this case, you don't need to call Remover()
more than once.
Hmm. let me try that.. Will update
Closing due to inactivity. Please open another issue if problem persists.
@plemeri First of all thank you for the work. Its really awesome
I am trying to use this but i am getting these errors and I cannot figure out from where we are using these. Can you please help me out.. This is in the backbones/SwinTransformer file