from fastai.vision.all import *
from fastai.vision import *
import pandas as pd
from fastdownload import download_url
#IMPORT HEADSHOT MODEL
HEADSHOT_PATH = 'DataCompiler\FramingMLModel\Data\Images\Headshot'
headshot_dls = ImageDataLoaders.from_folder(
path=HEADSHOT_PATH ,
item_tfms=Resize(224),
bs=16,
batch_tfms=[Normalize.from_stats(*imagenet_stats), RandTransform()],
valid_pct=0.2,
num_workers=0
)
model = vision_learner(dls=headshot_dls, arch=models.resnet50,metrics=[accuracy, error_rate])
headshot_model = model.load(f'model')
url = 'https://www.unh.edu/unhtoday/2019/07/build-your-professional-image-professional-headshot'
image_path = 'DataCompiler\FramingMLModel\TestData\\temp_image.jpg'
download_url(url, image_path, show_progress=False)
path = 'DataCompiler\FramingMLModel\TestData'
test_dls = ImageDataLoaders.from_folder(
path=path,
item_tfms=Resize(224),
bs=1,
batch_tfms=[Normalize.from_stats(*imagenet_stats), RandTransform()],
num_workers=0,
valid_pct=0
)
preds, _ = headshot_model.get_preds(dl=test_dls)
print(preds)
os.remove('DataCompiler\\TestData\\temp_image')
I am pretty new to FastAI so it may not make sense how I’m approaching the code.
I am trying to load a model I made in another file and test it on a single image to get a prediction. From what I understand, I need to load the original dls, set up the learner with the original dls, and then load the model into the learner.
I am then downloading a random image using download_url() and storing it locally so I can test it with the model. When I use ImageDataLoaders.from_folder() on the folder the new image is stored in, I am getting this error:
types = L(t if is_listy(t) else [t] for t in self.types).concat().unique()
TypeError: 'NoneType' object is not iterable
I don’t really know why this is happening, any advice would be great, thanks.