I'm currently trying to run a deep learning tool software that was previously created by someone else a few years ago. While trying to load a class called Evaluator which wraps all of the important mmdetection functions, I keep getting the following error: enter image description here
The model was downloaded automatically while running the code due to the following part of the config file:
model = dict(
type='FCOS',
pretrained='open-mmlab://detectron/resnet101_caffe',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
norm_cfg=dict(type='BN', requires_grad=False),
norm_eval=True,
style='caffe'),
neck=dict(
type='FPN',
in_channels=[256, 512, 1024, 2048],
out_channels=256,
start_level=1,
add_extra_convs=True,
extra_convs_on_inputs=False,
num_outs=5,
relu_before_extra_convs=True),
bbox_head=dict(
type='FCOSHead',
num_classes=15,
in_channels=256,
stacked_convs=4,
feat_channels=256,
strides=[8, 16, 32, 64, 128],
loss_cls=dict(
type='FocalLoss',
use_sigmoid=True,
gamma=2.0,
alpha=0.25,
loss_weight=1.0),
loss_bbox=dict(type='IoULoss', loss_weight=1.0),
loss_centerness=dict(
type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0)))
I'm not sure how to determine if the model I'm trying to load and the state dictionary are compatible or how to fix this problem. I'm new to deep learning and using MMdetection.
Here is part of the code from the utils.py file that contains the Evaluator class:
from skimage.draw import rectangle_perimeter
import skimage.io as io
from skimage.transform import resize
import numpy as np
import skimage
import pickle
import torch
from mmcv import Config, DictAction
from mmdet.models import build_detector
from mmcv.runner import load_checkpoint
import mmcv
from mmdet.datasets.pipelines import Compose # TO LOOK AT
from mmcv.parallel import collate, scatter
from mmdet.core import bbox2result
from skimage import data, io, filters
from matplotlib.pyplot import figure
import os
class_to_number = {"Yeast White": 0, "Budding White": 1, "Yeast Opaque": 2,
"Budding Opaque":3,"Yeast Gray": 4, "Budding Gray": 5,
"Shmoo":6,"Artifact": 7, "Unknown ": 8,
"Pseudohyphae": 9, "Hyphae": 10, "H-junction": 11,
"P-junction":12,"P-Start":13,"H-Start":14}
number_to_class = {y:x for x,y in class_to_number.items()}
class Evaluator():
def __init__(self,config,checkpoint_file):
self.cfg = Config.fromfile(config)
self.cfg["gpu-ids"] = 6
self.model = build_detector(
self.cfg.model, train_cfg=self.cfg.train_cfg, test_cfg=self.cfg.test_cfg)
checkpoint_dict = load_checkpoint(self.model,checkpoint_file)
state_dict = checkpoint_dict["state_dict"]
self.model.CLASSES = checkpoint_dict['meta']['CLASSES']
self.model.load_state_dict(state_dict)
self.model.eval()
I looked at the version of mmdet, mmcv, and pytorch to ensure they were the same versions that were used by the original creator of the software. I redownloaded the model file to ensure that it wasn't corrupted. `