question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: argument of type 'GeneralizedRCNN' is not iterable

See original GitHub issue

I trained a custom model for leukocytes detection. To save the model I use the following command"

##Full runnable code or full changes you made:

torch.save(trainer.model,path+"leukocytes.pth")
f = open(path+'leukocytes.yaml', 'w')
f.write(cfg.dump())
f.close()

Once the mode is saved I open a new notebook to run inference as follows:

from detectron2.utils.logger import setup_logger
setup_logger()
import cv2
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog

config_file_path = path+'leukocytes.yaml'

weights_path = path+'leukocytes.pth'

image_path = path+"testImages/data/small_lymphocytes_Image_22-02-22_at_10.36_AM.jpeg"

model = config_file_path
im = cv2.imread(image_path)
cfg = get_cfg()
cfg.merge_from_file(config_file_path)

cfg.MODEL.WEIGHTS = weights_path
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.8
predictor = DefaultPredictor(cfg)
outputs = predictor(im)
MetadataCatalog.get(cfg.DATASETS.TRAIN[0]).thing_classes = ['Leukocytes']
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
v = v.draw_instance_predictions(outputs["instances"].to("cpu"))
cv2.imshow('',v.get_image()[:, :, ::-1])
cv2.waitKey(0)



## __Full logs__ or other relevant observations:



TypeError Traceback (most recent call last) <ipython-input-52-26a8f28254df> in <module>() 20 cfg.MODEL.WEIGHTS = weights_path 21 cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.8 —> 22 predictor = DefaultPredictor(cfg) 23 outputs = predictor(im) 24 MetadataCatalog.get(cfg.DATASETS.TRAIN[0]).thing_classes = [‘Leukocytes’]

2 frames /usr/local/lib/python3.7/dist-packages/detectron2/checkpoint/detection_checkpoint.py in _load_file(self, filename) 41 42 loaded = super()._load_file(filename) # load native pth checkpoint —> 43 if “model” not in loaded: 44 loaded = {“model”: loaded} 45 return loaded

TypeError: argument of type ‘GeneralizedRCNN’ is not iterable

Environment:

sys.platform              linux
Python                    3.7.12 (default, Jan 15 2022, 18:48:18) [GCC 7.5.0]
numpy                     1.21.5
detectron2                0.1.3 @/usr/local/lib/python3.7/dist-packages/detectron2
detectron2 compiler       GCC 7.3
detectron2 CUDA compiler  10.1
detectron2 arch flags     sm_35, sm_37, sm_50, sm_52, sm_60, sm_61, sm_70, sm_75
DETECTRON2_ENV_MODULE     <not set>
PyTorch                   1.5.0+cu101 @/usr/local/lib/python3.7/dist-packages/torch
PyTorch debug build       False
CUDA available            True
GPU 0                     Tesla P100-PCIE-16GB
CUDA_HOME                 /usr/local/cuda
NVCC                      Build cuda_11.1.TC455_06.29190527_0
Pillow                    7.1.2
torchvision               0.6.0+cu101 @/usr/local/lib/python3.7/dist-packages/torchvision
torchvision arch flags    sm_35, sm_50, sm_60, sm_70, sm_75
fvcore                    0.1.5.post20220212
cv2                       4.1.2
------------------------  ---------------------------------------------------------------
PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) Math Kernel Library Version 2019.0.5 Product Build 20190808 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v0.21.1 (Git Hash 7d2fd500bc78936d1d648ca713b901012f470dbc)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 10.1
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
  - CuDNN 7.6.3
  - Magma 2.5.2
  - Build settings: BLAS=MKL, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -DNDEBUG -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DUSE_INTERNAL_THREADPOOL_IMPL -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_STATIC_DISPATCH=OFF, 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
ishank-junejacommented, Mar 5, 2022

I think we just need,

torch.save(trainer.model.state_dict(), "models/detectron/tmp.pt")

instead.

0reactions
shrutikapoyrekarcommented, Mar 7, 2022

So I used the model which is saved in cfg.OUTPUT_DIR and it works fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: argument of type 'int' is not iterable in indexing
Hello, I seem to be getting an error. The elements in O can vary. O = {1} or can be {3, 6, 9}....
Read more >
Argument of Type Bool is not iterable - Odoo
I am creating this excel report, when I used if condition for a field its showing the following error
Read more >
detectron2.config
Wrap a callable so that when it's called, the call will not be executed, but returns a dict that describes the call. LazyCall...
Read more >
See raw diff - Hugging Face
This groups portrait images together, and landscape images +# are not batched with portrait images. +_C.DATALOADER.ASPECT_RATIO_GROUPING = True + + +# ...
Read more >
计算机视觉:maskrcnn_benchmark代码平铺 - 51CTO博客
assert module_name not in module_dict ... an iterable of Tensors. ... raise TypeError("Unsupported type for to_image_list: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found