TypeError: 'dict' object is not callable

Hello,
I am working on object detection(YOLO) inside the ROS2 node. I trained my model from colab and load it in py. code. However, when I give an image inside the model, I got this error :

TypeError: ‘dict’ object is not callable

What is the solution in my case?


import torch
import torch.nn as nn
import os
import subprocess
import sys

import sys
sys.path.insert(0, '/home/mev/ObjectDetection/yolov7')

print(os.getcwd())
os.chdir(r"/home/mev/ObjectDetection/yolov7")
print(os.getcwd())
PATH = os.getcwd()


if torch.cuda.is_available():
    map_location=lambda storage, loc: storage.cuda()
else:
    map_location='cpu'
    
model = torch.load('./yolov7.pt', map_location=map_location)

print(model)

img_fdr="./image.png"

processed_image = model(img_fdr)

I guess torch.load will load a dict containing e.g. different state_dicts etc. while you are assuming it’s the model object.
Check the return value of torch.load('./yolov7.pt', map_location=map_location) and initialize a model manually if needed.

Thanks @ptrblck. I think, there is no problem related to loading model, cause I already print the model on the console. Additionally, I use Netron to see the model structure. Both of them looks fine. I think the problem is importing image frames to model. What should be the type to give image frames to model ?

Usually it would be a tensor while you are passing a file path as a string, so you might want to check if that’s the expected input type.