How to open an image stored in a dictionary using fastai? Please help

As of now I am using the below given code which is very inefficient, please help.
for t in frames_dict:

duration = t

img = frames_dict[t]

im1 =“geeks.jpg”)

img = open_image(‘geeks.jpg’)

pred_class,pred_idx,outputs = learn.predict(img)

preds =[to_data(pred_class)]


Let’s make that a bit more efficient, shall we? :slight_smile:

First, fastai has a concept of a test_dl, which no matter what your dataloader was made of, will accept items and preprocess it similar to your validation dataloader. So, we can do something like so:

dl = learn.dls.test_dl([f for f in frames_dict.values()])
preds = learn.get_preds(dl=dl)
preds = preds.argmax(dim=-1)
names = [learn.dls.vocab[i] for i in preds]

I can’t 100% be sure of what you’re doing, but this is a start.

Also, are you using fastai v1 or v2?

1 Like

I’m converting video to frames and storing it in dict .
I’m using v1.

I won’t be much help here then I’m afraid, sorry! I haven’t looked at v1 in many years now.

Hi @muellerzr
Im getting this error, can you help

Can’t pickle torch.half: attribute lookup half on main failed

DataBlock(blocks=(ImageBlock, MultiCategoryBlock),



             get_y=[[parent_label, multi_l]],

             item_tfms=RandomResizedCrop(460, min_scale=0.75),

            [*aug_transforms(size=224, max_warp=0), Normalize.from_stats(*imagenet_stats)])