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

AttributeError: 'NoneType' object has no attribute 'copy' #563

Open
undcloud opened this issue May 25, 2024 · 0 comments
Open

AttributeError: 'NoneType' object has no attribute 'copy' #563

undcloud opened this issue May 25, 2024 · 0 comments

Comments

@undcloud
Copy link

import os
import numpy as np
import torch
from ppq.api import load_onnx_graph, export_ppq_graph
from ppq.api.interface import dispatch_graph
from ppq.lib import Quantizer
from ppq.core import TargetPlatform
from ppq.executor import TorchExecutor
from ppq import QuantizationSettingFactory
import glob
from PIL import Image
import numpy as np


model_path = '/workspace/ppq/fan/Demoire_13-sim.onnx' # onnx simplified model
# data_path  = '/data/ImageNet/calibration' # calibration data folder
EXECUTING_DEVICE = 'cuda'

# initialize dataloader, suppose preprocessed calibration data is in binary format
INPUT_SHAPE = [1, 3, 1920, 1472]

img_list = glob.glob('/workspace/demoire/demoire/data/doc/*_moire.jpg')[0:10]
imgs = [ Image.open(i)  for i in img_list]
imgs = [ i.resize((1472, 1920))  for i in imgs]
imgs = [ np.array(i) for i in imgs]
imgs = [i[np.newaxis,:] for i in imgs ]
imgs = [np.transpose(i, [0,3,1,2]) for i in imgs ]
imgs = [ i/255.0 for i in imgs]
imgs = [ np.array(i,dtype=np.float32) for i in imgs]
# npy_array = [np.fromfile(os.path.join(data_path, file_name), dtype=np.float32).reshape(*INPUT_SHAPE) for file_name in os.listdir(data_path)]
dataloader = [torch.from_numpy(npy_tensor) for npy_tensor in imgs ] # [torch.from_numpy(np.load(npy_tensor)) for npy_tensor in npy_array]

# confirm platform and setting
target_platform = TargetPlatform.NCNN_INT8
setting = QuantizationSettingFactory.ncnn_setting()

# load and schedule graph
ppq_graph_ir = load_onnx_graph(model_path)
ppq_graph_ir = dispatch_graph(ppq_graph_ir, target_platform)

# intialize quantizer and executor
executor = TorchExecutor(ppq_graph_ir, device=EXECUTING_DEVICE)
quantizer = Quantizer(graph=ppq_graph_ir, platform=target_platform)

# run quantization
calib_steps = max(min(512, len(dataloader)), 8)     # 8 ~ 512
dummy_input = dataloader[0].to(EXECUTING_DEVICE)    # random input for meta tracing
ppq_graph_ir = quantizer.quantize(
        inputs=dummy_input,                         # some random input tensor, should be list or dict for multiple inputs
        calib_dataloader=dataloader,                # calibration dataloader
        executor=executor,                          # executor in charge of everywhere graph execution is needed
        setting=setting,                            # quantization setting
        calib_steps=calib_steps,                    # number of batched data needed in calibration, 8~512
        collate_fn=lambda x: x.to(EXECUTING_DEVICE), # final processing of batched data tensor
        
)

# export quantization param file and model file
export_ppq_graph(graph=ppq_graph_ir, platform=TargetPlatform.NCNN_INT8, graph_save_to='/workspace/ppq/fan/shufflenet-v2-sim-ppq', config_save_to='/workspace/ppq/fan/shufflenet-v2-sim-ppq.table')

root@8242142ab9f3:/workspace/ppq:
~python fan.py 
/workspace/ppq/ppq/__init__.py:10: UserWarning: You are importing ppq within its own root folder (/workspace/ppq). 
  warnings.warn(message.format(os.getcwd()))

      ____  ____  __   ____                    __              __
     / __ \/ __ \/ /  / __ \__  ______ _____  / /_____  ____  / /
    / /_/ / /_/ / /  / / / / / / / __ `/ __ \/ __/ __ \/ __ \/ /
   / ____/ ____/ /__/ /_/ / /_/ / /_/ / / / / /_/ /_/ / /_/ / /
  /_/   /_/   /_____\___\_\__,_/\__,_/_/ /_/\__/\____/\____/_/


[21:57:26] ncnn Format Gemm Pass Running ... Finished.
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_1/sam_blocks.0/Resize, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_1/sam_blocks.0/Resize_1, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_1/sam_blocks.0/Resize_2, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_1/sam_blocks.0/Resize_3, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_2/sam_blocks.0/Resize, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_2/sam_blocks.0/Resize_1, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_2/sam_blocks.0/Resize_2, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_2/sam_blocks.0/Resize_3, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_3/sam_blocks.0/Resize, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_3/sam_blocks.0/Resize_1, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_3/sam_blocks.0/Resize_2, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/encoder/encoder_3/sam_blocks.0/Resize_3, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_3/sam_blocks.0/Resize, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_3/sam_blocks.0/Resize_1, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_3/sam_blocks.0/Resize_2, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_3/sam_blocks.0/Resize_3, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_3/Resize, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_2/sam_blocks.0/Resize, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_2/sam_blocks.0/Resize_1, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_2/sam_blocks.0/Resize_2, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_2/sam_blocks.0/Resize_3, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_2/Resize, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_1/sam_blocks.0/Resize, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_1/sam_blocks.0/Resize_1, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_1/sam_blocks.0/Resize_2, recieving "None" at its input 1
[Warning] Unexpected input value of operation /ESDNet/decoder/decoder_1/sam_blocks.0/Resize_3, recieving "None" at its input 1
[Warning] Unexpected input value of operation /up/Resize, recieving "None" at its input 1
[21:57:28] PPQ Parameter Quantization Pass Running ...    Finished.
Calibration Progress(Phase 1): 100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [00:34<00:00,  3.48s/it]
Finished.
[21:58:05] PPQ Passive Parameter Quantization Running ... Finished.
[21:58:05] PPQ Parameter Baking Pass Running ...          Finished.
--------- Network Snapshot ---------
Num of Op:                    [414]
Num of Quantized Op:          [125]
Num of Variable:              [751]
Num of Quantized Var:         [498]
------- Quantization Snapshot ------
Num of Quant Config:          [500]
ACTIVATED:                    [125]
BAKED:                        [125]
FP32:                         [250]
Network Quantization Finished.
Traceback (most recent call last):
  File "fan.py", line 59, in <module>
    export_ppq_graph(graph=ppq_graph_ir, platform=TargetPlatform.NCNN_INT8, graph_save_to='/workspace/ppq/fan/shufflenet-v2-sim-ppq', config_save_to='/workspace/ppq/fan/shufflenet-v2-sim-ppq.table')
  File "/workspace/ppq/ppq/api/interface.py", line 589, in export_ppq_graph
    if copy_graph: graph = graph.copy()
AttributeError: 'NoneType' object has no attribute 'copy'

env: docker ppq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant