rockchip-linux / rknn-toolkit

BSD 3-Clause "New" or "Revised" License
820 stars 175 forks source link

rknn.build failure at Global Average Pool input height/width > 128 #156

Open ynjiun opened 2 years ago

ynjiun commented 2 years ago

I am running rknn toolkit for building a model.rknn for running on RK3566. After rknn.load_onnx() successfully, when run rknn.build(), the following error message occur:

--> Loading model: ./rknn_models/model_3566.onnx done
--> Building model E build: Global Average Pool input height/width > 128, which is not suppoted! E build: Catch exception when building RKNN model! E build: Traceback (most recent call last): E build:   File "rknn/api/rknn_base.py", line 2621, in rknn.api.rknn_base.RKNNBase.build E build:   File "rknn/api/graph_optimizer.py", line 3765, in rknn.api.graph_optimizer.GraphOptimizer.run E build:   File "rknn/api/graph_optimizer.py", line 3518, in rknn.api.graph_optimizer.GraphOptimizer._fuse_ops E build:   File "rknn/api/graph_optimizer.py", line 2210, in rknn.api.graph_optimizer._p_convert_global_avgpool_to_conv E build:   File "rknn/api/rknn_log.py", line 104, in rknn.api.rknn_log.RKNNLog.e E build: ValueError: Global Average Pool input height/width > 128, which is not suppoted! Build pytorch failed!

I checked my source code, I did not use the Global Average Pool anywhere. And actually I did explicitly remove final two layers of basenet (efficientnet) which contains global_pool by assigning them as Identity as below:

   basemodel_name = 'tf_efficientnet_b5_ap'
    print('Loading base model ()...'.format(basemodel_name), end='')
    basemodel = torch.hub.load('rwightman/gen-efficientnet-pytorch', basemodel_name, pretrained=True)
    print('Done.')

    # Remove last layer
    print('Removing last two layers (global_pool & classifier).')
    basemodel.global_pool = nn.Identity()
    basemodel.classifier = nn.Identity()

So it puzzled me why the rknn.build() would complain about the Global Average Pool at all.

Could anyone help to point me to the potential causes and possible fixes?

Thanks a lot for your help in advance.

zen-xingle commented 2 years ago

Hello! RK3566 using different RKNN_toolkit version. Which you can find here https://github.com/rockchip-linux/rknn-toolkit2. For RK3566, it would be better to ask question there. Also I had reminded my teammate of this issue. Thank you.

ynjiun commented 2 years ago

@zen-xingle, Thanks for the notes. I have moved this post to the issues under rknn-toolkit2.