2021-10-30 用torch.fx后量化的bug记录

  • 报错:ValueError: input model must be a GraphModule, please run torch._fx.symbolic_trace on your model before using quantize_fx. Got type:main.EVAL’>

原因:模型中有不是graph module的部分

解决方案:提供的torch._fx.symbolic_trace来看是哪个部分出问题了:

st = symbolic_trace(net)
print(st.graph)
print(st.code)
  • 报错:prepare_fx中assert isinstance(fn, FunctionType) AssertionError

原因:EVAL()对象不是FunctionType,不可调用

解决方案:只输入EVAL().model进行量化

  • 报错:RuntimeError: The archive ILSVRC2012_devkit_t12.tar.gz is not present in the root directory or is corrupted. You need to download it externally and place it in /mnt/OCR/ScriptId/imagenet.

原因:从服务器上拉下来的imagenet数据集格式与demo中的imagenet的数据集格式不匹配

解决方案:Issues with Dataloader for imagenet (should I use datasets.ImageFolder or datasets.ImageNet)?,将torchvision.datasets.ImageNet替换为这个example里的datasets.ImageFolder

  • 报错:RuntimeError: Found 0 images in subfolders of: ./data
    Supported image extensions are: .jpg,.JPG,.jpeg,.JPEG,.png,.PNG,.ppm,.PPM,.bmp,.BMP

原因:数据文件夹的结构不匹配

解决方案:RuntimeError: Found 0 images in subfolders of: ./data 数据集的文件夹结构一般是train/val->类别->图片,而不是train/val->图片。

  • 问题:imagenet数据集太大

解决方案:用tiny-imagenet-200或者抽部分imagenet数据集代替

你可能感兴趣的:(python,算法,Bug记录,python)