I tried to write a detect.py for faster-rcnn by myself, according to the demo. But when I load model, it doesn't work. I've run convert_caffe_pretrain.py and used vgg16_caffe.pth.
here is my detect.py:
from utils.config import opt
from model import FasterRCNNVGG16
from trainer import FasterRCNNTrainer
from data.util import read_image
from utils.vis_tool import vis_bbox
from utils import array_tool as at
import cv2
trainer.load('ckpts/vgg16_caffe.pth')
opt.caffe_pretrain = True # this model was trained from caffe-pretrained model
_bboxes, _labels, _scores = trainer.faster_rcnn.predict(img, visualize=True)
I tried to write a detect.py for faster-rcnn by myself, according to the demo. But when I load model, it doesn't work. I've run convert_caffe_pretrain.py and used vgg16_caffe.pth.
here is my detect.py: from utils.config import opt from model import FasterRCNNVGG16 from trainer import FasterRCNNTrainer from data.util import read_image from utils.vis_tool import vis_bbox from utils import array_tool as at import cv2
img = cv2.imread("./70.jpg") img = torch.from_numpy(img)[None]
faster_rcnn = FasterRCNNVGG16() trainer = FasterRCNNTrainer(faster_rcnn).cuda()
trainer.load('ckpts/vgg16_caffe.pth') opt.caffe_pretrain = True # this model was trained from caffe-pretrained model _bboxes, _labels, _scores = trainer.faster_rcnn.predict(img, visualize=True)
vis_bbox(at.tonumpy(img[0]), at.tonumpy(_bboxes[0]), at.tonumpy(_labels[0]).reshape(-1), at.tonumpy(_scores[0]).reshape(-1))
and here is wrong info: RuntimeError: Error(s) in loading state_dict for FasterRCNNVGG16: Missing key(s) in state_dict: "extractor.0.weight", "extractor.0.bias", "extractor.2.weight", "extractor.2.bias", "extractor.5.weight", "extractor.5.bias", "extractor.7.weight", "extractor.7.bias", "extractor.10.weight", "extractor.10.bias", "extractor.12.weight", "extractor.12.bias", "extractor.14.weight", "extractor.14.bias", "extractor.17.weight", "extractor.17.bias", "extractor.19.weight", "extractor.19.bias", "extractor.21.weight", "extractor.21.bias", "extractor.24.weight", "extractor.24.bias", "extractor.26.weight", "extractor.26.bias", "extractor.28.weight", "extractor.28.bias", "rpn.conv1.weight", "rpn.conv1.bias", "rpn.score.weight", "rpn.score.bias", "rpn.loc.weight", "rpn.loc.bias", "head.classifier.0.weight", "head.classifier.0.bias", "head.classifier.2.weight", "head.classifier.2.bias", "head.cls_loc.weight", "head.cls_loc.bias", "head.score.weight", "head.score.bias". Unexpected key(s) in state_dict: "features.0.weight", "features.0.bias", "features.2.weight", "features.2.bias", "features.5.weight", "features.5.bias", "features.7.weight", "features.7.bias", "features.10.weight", "features.10.bias", "features.12.weight", "features.12.bias", "features.14.weight", "features.14.bias", "features.17.weight", "features.17.bias", "features.19.weight", "features.19.bias", "features.21.weight", "features.21.bias", "features.24.weight", "features.24.bias", "features.26.weight", "features.26.bias", "features.28.weight", "features.28.bias", "classifier.6.weight", "classifier.6.bias", "classifier.0.weight", "classifier.0.bias", "classifier.3.weight", "classifier.3.bias".