Last active
August 11, 2020 04:41
-
-
Save qnkhuat/1e0704789bd4d5f312648b61541f5530 to your computer and use it in GitHub Desktop.
fastai predict array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastai.vision import Image,pil2tensor | |
import cv2 | |
def array2tensor(x): | |
""" Return an tensor image from cv2 array """ | |
x = cv2.cvtColor(x,cv2.COLOR_BGR2RGB) | |
return Image(pil2tensor(x,np.float32).div_(255)) | |
### USAGE | |
learn = load_learner(model_path,model_name) | |
# insert a new function to learner | |
learn.predict_array = types.MethodType( predict_array, learn ) | |
img = cv2.imread([IMAGE FILE NAME]) | |
learn.predict_array(img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment