Centernet: Demo Error : demo using own train VOC model

Created on 3 Dec 2019  路  3Comments  路  Source: xingyizhou/CenterNet

I want to demo own train_model on VOC but fault
$python demo.py ctdet --arch resdcn_18 --dataset pascal --demo../images/ --load_model ../exp/ctdet/pascal_resdcn18_512/model_last.pth

Fix size testing.
training chunk_sizes: [32]
The output will be saved to /workspace/chiu/CenterNet/src/lib/../../exp/ctdet/default
heads {'hm': 80, 'wh': 2, 'reg': 2}
Creating model...
=> loading pretrained model https://download.pytorch.org/models/resnet18-5c106cde.pth
=> init deconv weights from normal distribution
loaded ../exp/ctdet/pascal_resdcn18_512/model_last.pth, epoch 70
Skip loading parameter hm.2.weight, required shapetorch.Size([80, 64, 1, 1]), loaded shapetorch.Size([20, 64, 1, 1]). If you see this, your model does not fully load the pre-trained weight. Please make sure you have correctly specified --arch xxx or set the correct --num_classes for your own dataset.
Skip loading parameter hm.2.bias, required shapetorch.Size([80]), loaded shapetorch.Size([20]). If you see this, your model does not fully load the pre-trained weight. Please make sure you have correctly specified --arch xxx or set the correct --num_classes for your own dataset.

how to change shapetorch.Size([80, 64, 1, 1]) to shapetorch.Size([20, 64, 1, 1])???
thx

Most helpful comment

@ycxxn
@yhsmiley
I got the same issue, but I could solve it by changing demo.py file as follows.
This is because opts.init() overwrites [opt.dataset] with a default value, which is 'coco' in this case.
Use opt.parse() instead, and add some codes to initialize opt properly (refer to test.py, main.py)

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import _init_paths

import os
import cv2

from opts import opts
from datasets.dataset_factory import dataset_factory
from detectors.detector_factory import detector_factory

image_ext = ['jpg', 'jpeg', 'png', 'webp']
video_ext = ['mp4', 'mov', 'avi', 'mkv']
time_stats = ['tot', 'load', 'pre', 'net', 'dec', 'post', 'merge']

def demo(opt):
  os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str
  opt.debug = max(opt.debug, 1)

  Dataset = dataset_factory[opt.dataset]
  opt = opts().update_dataset_info_and_set_heads(opt, Dataset)
  print(opt)

  Detector = detector_factory[opt.task]
  detector = Detector(opt)

  if opt.demo == 'webcam' or \
    opt.demo[opt.demo.rfind('.') + 1:].lower() in video_ext:
    cam = cv2.VideoCapture(0 if opt.demo == 'webcam' else opt.demo)
    detector.pause = False
    while True:
        _, img = cam.read()
        cv2.imshow('input', img)
        ret = detector.run(img)
        time_str = ''
        for stat in time_stats:
          time_str = time_str + '{} {:.3f}s |'.format(stat, ret[stat])
        print(time_str)
        if cv2.waitKey(1) == 27:
            return  # esc to quit
  else:
    if os.path.isdir(opt.demo):
      image_names = []
      ls = os.listdir(opt.demo)
      for file_name in sorted(ls):
          ext = file_name[file_name.rfind('.') + 1:].lower()
          if ext in image_ext:
              image_names.append(os.path.join(opt.demo, file_name))
    else:
      image_names = [opt.demo]

    for (image_name) in image_names:
      ret = detector.run(image_name)
      time_str = ''
      for stat in time_stats:
        time_str = time_str + '{} {:.3f}s |'.format(stat, ret[stat])
      print(time_str)
if __name__ == '__main__':
  opt = opts().parse()
  demo(opt)

All 3 comments

You can try --num_classes 20.

Hi, after trying --num_classes 20 I get the following error:
error: unrecognized arguments: --num_classes 20

@ycxxn
@yhsmiley
I got the same issue, but I could solve it by changing demo.py file as follows.
This is because opts.init() overwrites [opt.dataset] with a default value, which is 'coco' in this case.
Use opt.parse() instead, and add some codes to initialize opt properly (refer to test.py, main.py)

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import _init_paths

import os
import cv2

from opts import opts
from datasets.dataset_factory import dataset_factory
from detectors.detector_factory import detector_factory

image_ext = ['jpg', 'jpeg', 'png', 'webp']
video_ext = ['mp4', 'mov', 'avi', 'mkv']
time_stats = ['tot', 'load', 'pre', 'net', 'dec', 'post', 'merge']

def demo(opt):
  os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str
  opt.debug = max(opt.debug, 1)

  Dataset = dataset_factory[opt.dataset]
  opt = opts().update_dataset_info_and_set_heads(opt, Dataset)
  print(opt)

  Detector = detector_factory[opt.task]
  detector = Detector(opt)

  if opt.demo == 'webcam' or \
    opt.demo[opt.demo.rfind('.') + 1:].lower() in video_ext:
    cam = cv2.VideoCapture(0 if opt.demo == 'webcam' else opt.demo)
    detector.pause = False
    while True:
        _, img = cam.read()
        cv2.imshow('input', img)
        ret = detector.run(img)
        time_str = ''
        for stat in time_stats:
          time_str = time_str + '{} {:.3f}s |'.format(stat, ret[stat])
        print(time_str)
        if cv2.waitKey(1) == 27:
            return  # esc to quit
  else:
    if os.path.isdir(opt.demo):
      image_names = []
      ls = os.listdir(opt.demo)
      for file_name in sorted(ls):
          ext = file_name[file_name.rfind('.') + 1:].lower()
          if ext in image_ext:
              image_names.append(os.path.join(opt.demo, file_name))
    else:
      image_names = [opt.demo]

    for (image_name) in image_names:
      ret = detector.run(image_name)
      time_str = ''
      for stat in time_stats:
        time_str = time_str + '{} {:.3f}s |'.format(stat, ret[stat])
      print(time_str)
if __name__ == '__main__':
  opt = opts().parse()
  demo(opt)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

wjx2 picture wjx2  路  7Comments

merckxiaan picture merckxiaan  路  7Comments

VRCMF picture VRCMF  路  6Comments

pipi2020 picture pipi2020  路  7Comments

Alexyitx picture Alexyitx  路  6Comments