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.

exporting faster_rcnn_fbnetv3g_fpn get a NotImplementedError: Could not run 'aten::_slow_conv2d_forward' with arguments from the 'QuantizedCPU' backend

See original GitHub issue

I used the demo to train and export faster_rcnn_fbnetv3g_fpn model using customized COCO datasets, got this error, all the other detection models works, code and error logs is as follows:

import os
import cv2
from detectron2.data.datasets import register_coco_instances
from detectron2.data import MetadataCatalog, DatasetCatalog
from detectron2.utils.visualizer import Visualizer, ColorMode
from d2go.model_zoo import model_zoo
import matplotlib.pyplot as plt
import copy
from detectron2.data import build_detection_test_loader
from d2go.export.api import convert_and_export_predictor
from d2go.utils.testing.data_loader_helper import create_fake_detection_data_loader
from d2go.export.d2_meta_arch import patch_d2_meta_arch
from mobile_cv.predictor.api import create_predictor
import logging
from d2go.utils.demo_predictor import DemoPredictor
from d2go.runner import GeneralizedRCNNRunner

register_coco_instances("my_dataset_train", {}, "/home/liupeng/sdb1/Image/ScaleDetection/Train/humanDetec/V4/Annotations/coco_info.json",
                        "/home/liupeng/sdb1/Image/ScaleDetection/Train/humanDetec/V4/AugImages")

model_name = "faster_rcnn_fbnetv3g_fpn.yaml"

def prepare_for_launch():
    runner = GeneralizedRCNNRunner()
    cfg = runner.get_default_cfg()
    cfg.merge_from_file(model_zoo.get_config_file(model_name))
    cfg.MODEL_EMA.ENABLED = False
    cfg.DATASETS.TRAIN = ("my_dataset_train",)
    cfg.DATASETS.TEST = ("my_dataset_train",)
    cfg.DATALOADER.NUM_WORKERS = 2
    cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url(model_name)  # Let training initialize from model zoo
    cfg.SOLVER.IMS_PER_BATCH = 1
    cfg.SOLVER.BASE_LR = 0.00025  # pick a good LR
    cfg.SOLVER.MAX_ITER = 1    # 600 iterations seems good enough for this toy dataset; you will need to train longer for a practical dataset
    cfg.SOLVER.STEPS = []        # do not decay learning rate
    cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128   # faster, and good enough for this toy dataset (default: 512)
    cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1  # only has one class (ballon). (see https://detectron2.readthedocs.io/tutorials/datasets.html#update-the-config-for-new-datasets)
    # NOTE: this config means the number of classes, but a few popular unofficial tutorials incorrect uses num_classes+1 here.
    os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
    return cfg, runner

cfg, runner = prepare_for_launch()
model = runner.build_model(cfg)
runner.do_train(cfg, model, resume=False)

# # disable all the warnings
previous_level = logging.root.manager.disable
logging.disable(logging.INFO)

patch_d2_meta_arch()

cfg_name = model_name
pytorch_model = model_zoo.get(cfg_name, trained=True)
pytorch_model.cpu()

with create_fake_detection_data_loader(224, 320, is_train=False) as data_loader:
    predictor_path = convert_and_export_predictor(
            model_zoo.get_config(cfg_name),
            copy.deepcopy(pytorch_model),
            "torchscript_int8@tracing",
            './',
            data_loader,
        )

# recover the logging level
logging.disable(previous_level)

model = create_predictor(predictor_path)

im = cv2.imread("/home/liupeng/sdb1/PythonProject/scaleDetection/data/images/12_20_09_24_087.jpg")
predictor = DemoPredictor(model)
outputs = predictor(im)
v = Visualizer(im,
                    MetadataCatalog.get("my_dataset_train"),
                    scale=1,
                    instance_mode=ColorMode.IMAGE
                    )
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
plt.imshow(out.get_image()[:, :, ::-1])
plt.show()

Traceback (most recent call last): File “/home/liupeng/sdb1/PythonProject/scaleDetection/detectron2go/fasterrcnn/train.py”, line 114, in <module> File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/d2go/export/api.py”, line 151, in convert_and_export_predictor return export_predictor(cfg, pytorch_model, predictor_type, output_dir, data_loader) File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/d2go/export/api.py”, line 174, in export_predictor return default_export_predictor( File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/d2go/export/api.py”, line 262, in default_export_predictor model_info = _export_single_model( File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/d2go/export/api.py”, line 196, in _export_single_model load_kwargs = model_export_method.export( File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/d2go/export/torchscript.py”, line 348, in new_f return old_f(cls, model, input_args, save_path, export_method, **export_kwargs) File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/d2go/export/torchscript.py”, line 209, in new_f outputs = model(*input_args) File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/torch/nn/modules/module.py”, line 1110, in _call_impl return forward_call(*input, **kwargs) File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/d2go/modeling/meta_arch/rcnn.py”, line 388, in forward return self.model.inference(inputs, do_postprocess=False)[0] File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/detectron2/modeling/meta_arch/rcnn.py”, line 200, in inference features = self.backbone(images.tensor) File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/torch/nn/modules/module.py”, line 1110, in _call_impl return forward_call(*input, **kwargs) File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/mobile_cv/arch/utils/quantize_utils.py”, line 345, in wrapped_method q_outputs = getattr(ModuleType, wrapped_method_name)(self, *q_args, **q_kwargs) File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/detectron2/modeling/backbone/fpn.py”, line 128, in forward prev_features = self.lateral_convs0 File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/torch/nn/modules/module.py”, line 1110, in _call_impl return forward_call(*input, **kwargs) File “/home/liupeng/anaconda3/envs/scaleDetection/lib/python3.9/site-packages/detectron2/layers/wrappers.py”, line 106, in forward x = F.conv2d( NotImplementedError: Could not run ‘aten::_slow_conv2d_forward’ with arguments from the ‘QuantizedCPU’ backend. This could be because the operator doesn’t exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. ‘aten::_slow_conv2d_forward’ is only available for these backends: [CPU, CUDA, BackendSelect, Python, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, AutogradHPU, AutogradNestedTensor, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode, Functionalize].

Expected behavior:

is it a config error?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wat3rBrocommented, Jan 11, 2022

@wat3rBro Any thoughts about this issue? Is that because of using FBNetV2FpnBackbone

@zhanghang1989 yes, it looks like issue from FPN, https://github.com/facebookresearch/d2go/pull/163 should fix it.

1reaction
zhanghang1989commented, Jan 10, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not run 'aten::_slow_conv2d_forward' with arguments ...
After convert(), I got the error when I tried to do inference. NotImplementedError: Could not run 'aten::_slow_conv2d_forward' with arguments ...
Read more >
Error while running YOLOv5 on Orin - NVIDIA Developer Forums
I got the following error: NotImplementedError: Could not run 'torchvision::nms' with arguments from the 'CUDA' backend.
Read more >
PyTorch Sparse : NotImplementedError: Could not run 'aten ...
When trying to take the autograd derivative for NotImplementedError: Could not run 'aten::is_coalesced' with arguments from the 'CUDA' ...
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