PaddlePaddle / PaddleClas

A treasure chest for visual classification and recognition powered by PaddlePaddle
Apache License 2.0
5.44k stars 1.17k forks source link

GoogLeNet无法训练. forward报错 #1671

Closed Water2style closed 2 years ago

Water2style commented 2 years ago

PaddleClas使用的 release/2.3版本

代码如下:

输入

inputs = [Input([None, 3, 224, 224], 'float32', name='image')] labels = [Input([None, 1], 'int64', name='label')]

net = PaddleClas.GoogLeNet() model = paddle.Model(net, inputs, labels)

优化器

optimizer = paddle.optimizer.Momentum( learning_rate=0.01, parameters=model.parameters())

model.prepare( optimizer, paddle.nn.CrossEntropyLoss(), paddle.metric.Accuracy(topk=(1, 5)))

略过准备数据集

model.fit(train_loader, epochs=50, verbose=1)

NOTE:model.eval也不行,同样的forward有错,怀疑是网络结构有问题? net那变量那里,换了几个其他模型,都不会报错

详细错误:

python 3.pretrain_test.py 3.pretrain_test.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp

                     Models supported by PaddleClas                         

+-------------------+----------------------------------------------------------+ | Series | Name | +-------------------+----------------------------------------------------------+ | AlexNet | AlexNet | | DarkNet | DarkNet53 | | DeiT | DeiT_base_distilled_patch16_224 | | | DeiT_base_distilled_patch16_384 DeiT_base_patch16_224 | | | DeiT_base_patch16_384 DeiT_small_distilled_patch16_224 | | | DeiT_small_patch16_224 DeiT_tiny_distilled_patch16_224 | | | DeiT_tiny_patch16_224 | | DenseNet | DenseNet121 DenseNet161 DenseNet169 DenseNet201 | | | DenseNet264 | | DLA | DLA46_c DLA60x_c DLA34 DLA60 DLA60x DLA102 DLA102x | | | DLA102x2 DLA169 | | DPN | DPN68 DPN92 DPN98 DPN107 DPN131 | | EfficientNet | EfficientNetB0 EfficientNetB0_small EfficientNetB1 | | | EfficientNetB2 EfficientNetB3 EfficientNetB4 | | | EfficientNetB5 EfficientNetB6 EfficientNetB7 | | ESNet | ESNet_x0_25 ESNet_x0_5 ESNet_x0_75 ESNet_x1_0 | | GhostNet | GhostNet_x0_5 GhostNet_x1_0 GhostNet_x1_3 | | | GhostNet_x1_3_ssld | | HarDNet | HarDNet39_ds HarDNet68_ds HarDNet68 HarDNet85 | | HRNet | HRNet_W18_C HRNet_W30_C HRNet_W32_C HRNet_W40_C | | | HRNet_W44_C HRNet_W48_C HRNet_W64_C HRNet_W18_C_ssld | | | HRNet_W48_C_ssld | | Inception | GoogLeNet InceptionV3 InceptionV4 | | MixNet | MixNet_S MixNet_M MixNet_L | | MobileNetV1 | MobileNetV1_x0_25 MobileNetV1_x0_5 MobileNetV1_x0_75 | | | MobileNetV1 MobileNetV1_ssld | | MobileNetV2 | MobileNetV2_x0_25 MobileNetV2_x0_5 MobileNetV2_x0_75 | | | MobileNetV2 MobileNetV2_x1_5 MobileNetV2_x2_0 | | | MobileNetV2_ssld | | MobileNetV3 | MobileNetV3_small_x0_35 MobileNetV3_small_x0_5 | | | MobileNetV3_small_x0_75 MobileNetV3_small_x1_0 | | | MobileNetV3_small_x1_25 MobileNetV3_large_x0_35 | | | MobileNetV3_large_x0_5 MobileNetV3_large_x0_75 | | | MobileNetV3_large_x1_0 MobileNetV3_large_x1_25 | | | MobileNetV3_small_x1_0_ssld MobileNetV3_large_x1_0_ssld | | PPLCNet | PPLCNet_x0_25 PPLCNet_x0_35 PPLCNet_x0_5 | | | PPLCNet_x0_75 PPLCNet_x1_0 PPLCNet_x1_5 PPLCNet_x2_0 | | | PPLCNet_x2_5 | | RedNet | RedNet26 RedNet38 RedNet50 RedNet101 RedNet152 | | RegNet | RegNetX_4GF | | Res2Net | Res2Net50_14w_8s Res2Net50_26w_4s Res2Net50_vd_26w_4s | | | Res2Net200_vd_26w_4s Res2Net101_vd_26w_4s | | | Res2Net50_vd_26w_4s_ssld Res2Net101_vd_26w_4s_ssld | | | Res2Net200_vd_26w_4s_ssld | | ResNeSt | ResNeSt50 ResNeSt50_fast_1s1x64d | | ResNet | ResNet18 ResNet18_vd ResNet34 ResNet34_vd ResNet50 | | | ResNet50_vc ResNet50_vd ResNet50_vd_v2 ResNet101 | | | ResNet101_vd ResNet152 ResNet152_vd ResNet200_vd | | | ResNet34_vd_ssld ResNet50_vd_ssld ResNet50_vd_ssld_v2 | | | ResNet101_vd_ssld Fix_ResNet50_vd_ssld_v2 | | | ResNet50_ACNet_deploy | | ResNeXt | ResNeXt50_32x4d ResNeXt50_vd_32x4d ResNeXt50_64x4d | | | ResNeXt50_vd_64x4d ResNeXt101_32x4d | | | ResNeXt101_vd_32x4d ResNeXt101_32x8d_wsl | | | ResNeXt101_32x16d_wsl ResNeXt101_32x32d_wsl | | | ResNeXt101_32x48d_wsl Fix_ResNeXt101_32x48d_wsl | | | ResNeXt101_64x4d ResNeXt101_vd_64x4d ResNeXt152_32x4d | | | ResNeXt152_vd_32x4d ResNeXt152_64x4d | | | ResNeXt152_vd_64x4d | | ReXNet | ReXNet_1_0 ReXNet_1_3 ReXNet_1_5 ReXNet_2_0 | | | ReXNet_3_0 | | SENet | SENet154_vd SE_HRNet_W64_C_ssld SE_ResNet18_vd | | | SE_ResNet34_vd SE_ResNet50_vd SE_ResNeXt50_32x4d | | | SE_ResNeXt50_vd_32x4d SE_ResNeXt101_32x4d | | ShuffleNetV2 | ShuffleNetV2_swish ShuffleNetV2_x0_25 | | | ShuffleNetV2_x0_33 ShuffleNetV2_x0_5 ShuffleNetV2_x1_0 | | | ShuffleNetV2_x1_5 ShuffleNetV2_x2_0 | | SqueezeNet | SqueezeNet1_0 SqueezeNet1_1 | | SwinTransformer | SwinTransformer_large_patch4_window7_224_22kto1k | | | SwinTransformer_large_patch4_window12_384_22kto1k | | | SwinTransformer_base_patch4_window7_224_22kto1k | | | SwinTransformer_base_patch4_window12_384_22kto1k | | | SwinTransformer_base_patch4_window12_384 | | | SwinTransformer_base_patch4_window7_224 | | | SwinTransformer_small_patch4_window7_224 | | | SwinTransformer_tiny_patch4_window7_224 | | Twins | pcpvt_small pcpvt_base pcpvt_large alt_gvt_small | | | alt_gvt_base alt_gvt_large | | VGG | VGG11 VGG13 VGG16 VGG19 | | VisionTransformer | ViT_base_patch16_224 ViT_base_patch16_384 | | | ViT_base_patch32_384 ViT_large_patch16_224 | | | ViT_large_patch16_384 ViT_large_patch32_384 | | | ViT_small_patch16_224 | | Xception | Xception41 Xception41_deeplab Xception65 | | | Xception65_deeplab Xception71 | +-------------------+----------------------------------------------------------+ Powered by PaddlePaddle!

W0206 21:22:07.875423 94955 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.5, Driver API Version: 11.2, Runtime API Version: 11.1 W0206 21:22:07.877460 94955 device_context.cc:465] device: 0, cuDNN Version: 8.1. The loss value printed in the log is the current step, and the metric is the average value of previous steps. Epoch 1/50 /home/xieyunyao/miniconda3/envs/PP22/lib/python3.8/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: np.object is a deprecated alias for the builtin object. To silence this warning, use object by itself. Doing this will not modify any behavior and is safe. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations if data.dtype == np.object: /home/xieyunyao/miniconda3/envs/PP22/lib/python3.8/site-packages/paddle/fluid/layers/utils.py:77: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working return (isinstance(seq, collections.Sequence) and Traceback (most recent call last): File "3.pretrain_test.py", line 134, in model.fit(train_loader, epochs=50, verbose=1) File "/home/xieyunyao/miniconda3/envs/PP22/lib/python3.8/site-packages/paddle/hapi/model.py", line 1732, in fit logs = self._run_one_epoch(train_loader, cbks, 'train') File "/home/xieyunyao/miniconda3/envs/PP22/lib/python3.8/site-packages/paddle/hapi/model.py", line 2062, in _run_one_epoch outs = getattr(self, mode + '_batch')(_inputs) File "/home/xieyunyao/miniconda3/envs/PP22/lib/python3.8/site-packages/paddle/hapi/model.py", line 1061, in train_batch loss = self._adapter.train_batch(inputs, labels, update) File "/home/xieyunyao/miniconda3/envs/PP22/lib/python3.8/site-packages/paddle/hapi/model.py", line 716, in train_batch losses = self.model._loss((to_list(outputs) + labels)) File "/home/xieyunyao/miniconda3/envs/PP22/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 914, in call outputs = self.forward(*inputs, **kwargs) TypeError: forward() takes 3 positional arguments but 5 were given

weisy11 commented 2 years ago

你好,GoogleNet模型不支持paddle.Model接口 具体原因: GoogleNet的输出有多个,但是paddle.Model需要模型的输出是单一的 可以参考:https://github.com/PaddlePaddle/PaddleClas/blob/release/2.3/ppcls/arch/backbone/model_zoo/googlenet.py