Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug for show_result_pyplot(): 'EncoderDecoder' object has no attribute 'dataset_meta' #2299

Closed
VoyagerXvoyagerx opened this issue Nov 12, 2022 · 5 comments

Comments

@VoyagerXvoyagerx
Copy link
Contributor

VoyagerXvoyagerx commented Nov 12, 2022

classes=model.dataset_meta['classes'],

When running the https:/open-mmlab/mmsegmentation/blob/dev-1.x/demo/MMSegmentation_Tutorial.ipynb , an attribute error came.

When I referred to the doc and https://mmsegmentation.readthedocs.io/zh_CN/dev-1.x/_modules/mmseg/models/segmentors/encoder_decoder.html#EncoderDecoder (souce code) , I did not find the attribute'dataset_meta'.

  1. What command or script did you run?
    https:/open-mmlab/mmsegmentation/blob/dev-1.x/demo/MMSegmentation_Tutorial.ipynb

  2. Did you make any modifications on the code or config? Did you understand what you have modified?
    no modifications.

  3. What dataset did you use?
    iccv09Data

Environment
sys.platform: linux
Python: 3.8.10 (default, Jun 4 2021, 15:09:15) [GCC 7.5.0]
CUDA available: True
numpy_random_seed: 2147483648
GPU 0: NVIDIA GeForce RTX 2080 Ti
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 11.3, V11.3.109
GCC: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
PyTorch: 1.11.0+cu113
PyTorch compiling details: PyTorch built with:

  • GCC 7.3
  • C++ Version: 201402
  • Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
  • Intel(R) MKL-DNN v2.5.2 (Git Hash a9302535553c73243c632ad3c4c80beec3d19a1e)
  • OpenMP 201511 (a.k.a. OpenMP 4.5)
  • LAPACK is enabled (usually provided by MKL)
  • NNPACK is enabled
  • CPU capability usage: AVX2
  • CUDA Runtime 11.3
  • 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_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
  • CuDNN 8.2
  • Magma 2.5.2
  • Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.2.0, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -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-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -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, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.11.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF,

TorchVision: 0.12.0+cu113
OpenCV: 4.6.0
MMEngine: 0.3.1
MMSegmentation: 1.0.0rc1+7927591

Error traceback

/root/miniconda3/lib/python3.8/site-packages/mmengine/visualization/visualizer.py:170: UserWarning: `Visualizer` backend is not initialized because save_dir is None.
  warnings.warn('`Visualizer` backend is not initialized '
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [32], line 9
      7 result = inference_model(model, img)
      8 plt.figure(figsize=(8, 6))
----> 9 vis_result = show_result_pyplot(model, img, result, palette)
     10 plt.imshow(mmcv.bgr2rgb(vis_result))

File ~/mmsegmentation/mmseg/apis/inference.py:197, in show_result_pyplot(model, img, result, opacity, title, draw_gt, draw_pred, wait_time, show, save_dir, out_file)
    191 # init visualizer
    192 visualizer = SegLocalVisualizer(
    193     vis_backends=[dict(type='LocalVisBackend')],
    194     save_dir=save_dir,
    195     alpha=opacity)
    196 visualizer.dataset_meta = dict(
--> 197     classes=model.dataset_meta['classes'],
    198     palette=model.dataset_meta['palette'])
    199 visualizer.add_datasample(
    200     name=title,
    201     image=image,
   (...)
    206     out_file=out_file,
    207     show=show)
    208 vis_img = visualizer.get_image()

File ~/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py:1185, in Module.__getattr__(self, name)
   1183     if name in modules:
   1184         return modules[name]
-> 1185 raise AttributeError("'{}' object has no attribute '{}'".format(
   1186     type(self).__name__, name))

AttributeError: 'EncoderDecoder' object has no attribute 'dataset_meta'
<Figure size 800x600 with 0 Axes>
@sanbuphy
Copy link

you can refer to this :https:/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py#L1939

@VoyagerXvoyagerx
Copy link
Contributor Author

VoyagerXvoyagerx commented Nov 13, 2022

Thanks a lot! I read the code you referred to and added cfg.train_dataloader.dataset.metainfo = metainfo in the cfg, but the same error occurred.
In runner.py #L2098 , train_dataloader.dataset.metainfo is assigned to checkpoint.meta.dataset_meta , but model.dataset_meta is not assigned, while in show_result_pyplot(), inference.py#L148 I could not find chekpoint loaded to get dataset_meta. That maybe why my modification did not work.
fix
assign metainfo (a dict with two keys) to model.dataset_meta before excuting show_result_pyplot() .

result = inference_model(model, img)
plt.figure(figsize=(8, 6))
model.dataset_meta = dict(classes = classes, palette = palette)
vis_result = show_result_pyplot(model, img, result, save_dir='result_demo.jpg')
plt.imshow(mmcv.bgr2rgb(vis_result))

@sanbuphy
Copy link

Thanks a lot! I read the code you referred to and added cfg.train_dataloader.dataset.metainfo = metainfo in the cfg, but the same error occurred. In runner.py #L2098 , train_dataloader.dataset.metainfo is assigned to checkpoint.meta.dataset_meta , but model.dataset_meta is not assigned, while in show_result_pyplot(), inference.py#L148 I could not find chekpoint loaded to get dataset_meta. That maybe why my modification did not work. fix assign metainfo (a dict with two keys) to model.dataset_meta before excuting show_result_pyplot() .

result = inference_model(model, img)
plt.figure(figsize=(8, 6))
model.dataset_meta = dict(classes = classes, palette = palette)
vis_result = show_result_pyplot(model, img, result, save_dir='result_demo.jpg')
plt.imshow(mmcv.bgr2rgb(vis_result))

The genuine model.dataset_meta just like :
{'CLASSES':('xxx','xxxx'),'PALETTE':[xxxxxx]}
maybe you can change dict(classes = classes, palette = palette) into dict('CLASSES' = classes, 'PALETTE' = palette)
and the palette can be set to None.

In addition, you can make sure the dataset_meta is in your config.
in config they named 'metainfo' , there are four occurrences in the complete configuration:‘train_dataloader/val/test’ and Outermost layer metainfo.

@VoyagerXvoyagerx
Copy link
Contributor Author

#2326
Thanks for your suggestion! I found dataset_meta saved in the checkpoint. So we should init model from the checkpoint before visualization. I have made a pull request to fix the bug in this tutorial.

@xiexinch
Copy link
Collaborator

xiexinch commented Dec 2, 2022

#2326

Closing the issue, as there is no activity for a while.
We hope your issue has been resolved.
If not, please feel free to open a new one.

@xiexinch xiexinch closed this as completed Dec 2, 2022
wjkim81 pushed a commit to wjkim81/mmsegmentation that referenced this issue Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants