Closed lucasgabrielce closed 4 years ago
Good catch! Thanks! I reverted the get_preds to what fastai uses, but forgot an import. I’ll fix the import then would appreciate it if you could let me know how it compares to fastai :)
Pushed the fix, let me know if upgrading it via pip helps
BTW: It's untested if cv2
works. The fastai library (and this library) are tested with Pillow
I pushed the fix via pip with pip install fastinference -U
, however now I can't import it.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-10-40720c496b58> in <module>
----> 1 from fastinference.inference import *
~/miniconda3/envs/fastai2/lib/python3.6/site-packages/fastinference/inference/__init__.py in <module>
----> 1 from .inference import *
2 from .text import *
~/miniconda3/envs/fastai2/lib/python3.6/site-packages/fastinference/inference/inference.py in <module>
9
10 # Cell
---> 11 from fastai.learner import _ConstantFuncnstantFunc
12 from fastai.vision.all import *
13 from fastai.tabular.all import *
ImportError: cannot import name '_ConstantFuncnstantFunc'
I tried to downgrade my fastai version (2.0.13 to 2.0.8 and to 2.0.7) and it did not work, same error.
About the cv2
I can use it normally with fastai predict
(cv2.imread
to feed it). I'm gonna be careful and start to use PIL if possible. Thanks.
facepalm no I hit tab complete and didn't pay attention
Re: cv2, if it works don't worry about it then :) Just know fastai does it's stuff with Pillow
Okay, just pushed another update.
I updated and could not only import it but run it also! I'm going to do some experiments now with some data and I'll update you asap. Thank you!
About the cv2 again, haha: I remember that my friend and I, in our work, we tried to use PIL but it was slower than cv2. But cv2 uses BGR in default not RGB, so this is a problem if you forget to call it the right way, that's why I said I'd try to use PIL in a daily basis with fastai.
[]'s from Brazil! Thank you again
Make sure to also use the performance-boosted Pillow SIMD: https://pypi.org/project/Pillow-SIMD/
from fastinference.inference import *
(worked fine)%%time for i in range(40): learn.predict(img)
This code returned:
It seems that to run a predict with fastinference I need to have a databunch loaded with the learner itself.
The steps I followed: 1 - Import fastai 2 - Load a pre-trained model (this model was exported with
.export()
) withlearn = load_learner('PATH_OF_LEARNER', cpu=False)
3 - Predict with a image loaded with opencv (cv2.imread(image_path)
) 4 - Import fastinference withfrom fastinference.inference import *
(no error returned) 5 - Repeat step 3 and got the error.