Closed tann9949 closed 2 years ago
I've dig on this bug a little more, it seems that the model failed to forward after the function to_static
was called. I assumed that somehow to_statc
function breaks the forward pipeline?
This looks like #4658
From what I have debugged, it seems that the to_static
function causing the input that parsed on ImSeq
class (at PaddleOCR/ppocr/modeling/neck/rnn.py
to be tuple
instead of paddle's Tensor.
I got this fixed by modifying ImSeq
class as follows:
class Im2Seq(nn.Layer):
def __init__(self, in_channels, **kwargs):
super().__init__()
self.out_channels = in_channels
def forward(self, x):
if isinstance(x, tuple):
x = x[0]
B, C, H, W = x.shape
assert H == 1
x = x.squeeze(axis=2)
x = x.transpose([0, 2, 1]) # (NTC)(batch, width, channels)
return x
and now things work just fine. I personally think this is not a good solution, but i'll let the Paddle team decide on this issue. Closing.
:mage: 请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem
Hi, I was trying to export my trained
det_r50_dcn_fce_ctw
model and faced the issue when trying to export the model.I use the code modified from
tools/export_model.py
.:computer: Here's my code:
The code bugged on the last line `export_single_model` ```python from ppocr.modeling.architectures import build_model from ppocr.postprocess import build_post_process from ppocr.utils.save_load import load_model from ppocr.utils.logging import get_logger from tools.program import load_config, merge_config, ArgsParser from tools.export_model import export_single_model class FLAGS: config = "configs/rec/rec_svtrnet-wandb.yml" profiler_options = None opt = {} config = load_config(FLAGS.config) config = merge_config(config, FLAGS.opt) logger = get_logger() post_process_class = build_post_process(config["PostProcess"], config["Global"]) # build character assert hasattr(post_process_class, "character") char_num = len(getattr(post_process_class, "character")) config["Architecture"]["Head"]["out_channels"] = char_num model = build_model(config["Architecture"]) load_model(config, model, model_type="rec") model.eval() save_path = config["Global"]["save_inference_dir"] arch_config = config["Architecture"] save_path = os.path.join(save_path, "inference") export_single_model(model, arch_config, save_path, logger) ```:wrench: Here's my config file:
```yaml Global: use_gpu: true epoch_num: 1500 log_smooth_window: 20 print_batch_step: 20 save_model_dir: ./output/det_r50_dcn_fce_ctw/ save_epoch_step: 100 # evaluation is run every 835 iterations eval_batch_step: [0, 835] cal_metric_during_train: False pretrained_model: ./pretrain_models/ResNet50_vd_ssld_pretrained checkpoints: ./output/det_r50_dcn_fce_ctw/latest save_inference_dir: output/det_r50_dcn_fce_ctw/inference use_visualdl: False infer_img: doc/imgs_en/img_10.jpg save_res_path: ./output/det_fce/prediacts_fce.txt use_wandb: True wandb: project: det_r50_dcn_fce_ctw name: trial_run entity: my-entity Architecture: model_type: det algorithm: FCE Transform: Backbone: name: ResNet layers: 50 dcn_stage: [False, True, True, True] out_indices: [1,2,3] Neck: name: FCEFPN out_channels: 256 has_extra_convs: False extra_stage: 0 Head: name: FCEHead fourier_degree: 5 Loss: name: FCELoss fourier_degree: 5 num_sample: 50 Optimizer: name: Adam beta1: 0.9 beta2: 0.999 lr: learning_rate: 0.0001 regularizer: name: 'L2' factor: 0 PostProcess: name: FCEPostProcess scales: [8, 16, 32] alpha: 1.0 beta: 1.0 fourier_degree: 5 box_type: 'poly' Metric: name: DetFCEMetric main_indicator: hmean Train: dataset: name: SimpleDataSet data_dir: ./train_data/ctw1500/imgs/ label_file_list: - ./train_data/ctw1500/imgs/training.txt transforms: - DecodeImage: # load image img_mode: BGR channel_first: False ignore_orientation: True - DetLabelEncode: # Class handling label - ColorJitter: brightness: 0.142 saturation: 0.5 contrast: 0.5 - RandomScaling: - RandomCropFlip: crop_ratio: 0.5 - RandomCropPolyInstances: crop_ratio: 0.8 min_side_ratio: 0.3 - RandomRotatePolyInstances: rotate_ratio: 0.5 max_angle: 30 pad_with_fixed_color: False - SquareResizePad: target_size: 800 pad_ratio: 0.6 - IaaAugment: augmenter_args: - { 'type': Fliplr, 'args': { 'p': 0.5 } } - FCENetTargets: fourier_degree: 5 - NormalizeImage: scale: 1./255. mean: [0.485, 0.456, 0.406] std: [0.229, 0.224, 0.225] order: 'hwc' - ToCHWImage: - KeepKeys: keep_keys: ['image', 'p3_maps', 'p4_maps', 'p5_maps'] # dataloader will return list in this order loader: shuffle: True drop_last: False batch_size_per_card: 6 num_workers: 8 Eval: dataset: name: SimpleDataSet data_dir: ./train_data/ctw1500/imgs/ label_file_list: - ./train_data/ctw1500/imgs/test.txt transforms: - DecodeImage: # load image img_mode: BGR channel_first: False ignore_orientation: True - DetLabelEncode: # Class handling label - DetResizeForTest: limit_type: 'min' limit_side_len: 736 - NormalizeImage: scale: 1./255. mean: [0.485, 0.456, 0.406] std: [0.229, 0.224, 0.225] order: 'hwc' - Pad: - ToCHWImage: - KeepKeys: keep_keys: ['image', 'shape', 'polys', 'ignore_tags'] loader: shuffle: False drop_last: False batch_size_per_card: 1 # must be 1 num_workers: 2 ```:bug: The code raised the following error:
``` --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /tmp/ipykernel_252/2829029886.py in:palm_tree: Environments
registry.baidubce.com/paddlepaddle/paddle:2.1.3-gpu-cuda11.2-cudnn8
paddlepaddle-gpu==2.1.3.post112
: PaddleOCR 2.5: 问题相关组件/Related components: