xuebinqin / U-2-Net

The code for our newly accepted paper in Pattern Recognition 2020: "U^2-Net: Going Deeper with Nested U-Structure for Salient Object Detection."
Apache License 2.0
8.43k stars 1.45k forks source link

The model size is 4.52MB instead of 4.7MB #279

Open seorim0 opened 2 years ago

seorim0 commented 2 years ago

First of all, thank you for such a wonderful project. I have one question regarding the model size. I used a lightweight version of U2-Net(U2NETP), and the size of the model comes out to be 4.52 MB. This is different from the 4.7 MB mentioned in your paper.

I didn't change anything except in_ch and out_ch to 1 in U2NETP. This alone cannot make a difference of 0.2 MB. Could you please tell me the reason for this difference? Please let me know if I'm wrong or if there's something I need to check.

Here is the code I used to check the model parameters:

# calculate the size of total network
def cal_total_params(our_model):
    total_parameters = 0
    for variable in our_model.parameters():
        shape = variable.size()
        variable_parameters = 1
        for dim in shape:
            variable_parameters *= dim
        total_parameters += variable_parameters

    return total_parameters
xuebinqin commented 2 years ago

Thanks for your interest. The model size in terms of MB is dependent on the OS. It may vary a little bit. The number of MB is just to provide the users an intuitive understanding. If you need more specific scale of model, you could try to calculate the GLOPS or the parameter numbers.

On Thu, Jan 6, 2022 at 5:39 AM Seo-Rim Hwang @.***> wrote:

First of all, thank you for such a wonderful project. I have one question regarding the model size. I used a lightweight version of U2-Net, and the size of the model comes out to be 4.52 MB. This is different from the 4.7 MB mentioned in your paper.

I haven't made any changes to it, could you tell me the reason for this difference? Please let me know if I'm wrong or if there's something I need to check.

Here is the code I used to check the model parameters:

calculate the size of total network

def cal_total_params(our_model): total_parameters = 0 for variable in our_model.parameters(): shape = variable.size() variable_parameters = 1 for dim in shape: variable_parameters *= dim total_parameters += variable_parameters

return total_parameters

— Reply to this email directly, view it on GitHub https://github.com/xuebinqin/U-2-Net/issues/279, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSGORKNXUZXL3LQHAC3FMDUUTXF5ANCNFSM5LLIAJ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Xuebin Qin PhD Department of Computing Science University of Alberta, Edmonton, AB, Canada Homepage: https://xuebinqin.github.io/

seorim0 commented 2 years ago

@xuebinqin

Thank you for the reply!
Then is it correct the total number of parameters is about 1.13M?

xuebinqin commented 2 years ago

u're welcome. We didn't check that. Because we think this parameter number does not seem that important in real-world applications. Because it won't directly tell users either how much storage or how much computation costs are needed. So we only use the MB and time costs to quantify the model efficiency explicitly.

On Thu, Jan 6, 2022 at 11:42 AM Seo-Rim Hwang @.***> wrote:

@xuebinqin https://github.com/xuebinqin

Thank you for the reply! Then is it correct the total number of parameters is about 1.13M?

— Reply to this email directly, view it on GitHub https://github.com/xuebinqin/U-2-Net/issues/279#issuecomment-1006348383, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSGORJKABBEQLFVS55ITTLUUVBVLANCNFSM5LLIAJ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

-- Xuebin Qin PhD Department of Computing Science University of Alberta, Edmonton, AB, Canada Homepage: https://xuebinqin.github.io/

seorim0 commented 2 years ago

@xuebinqin

I understand. I'm researching the field of speech processing, and I want to use this network for the speech area. So, I kept asking if I was applying it wrong.. Thank you for always answering my questions!

xuebinqin commented 2 years ago

u're very welcome.

All the best.

On Fri, Jan 7, 2022 at 6:50 AM Seo-Rim Hwang @.***> wrote:

@xuebinqin https://github.com/xuebinqin

I understand. I'm researching the field of speech processing, and I want to use this network for the speech area. So, I kept asking if I was applying it wrong.. Thank you for always answering my questions!

— Reply to this email directly, view it on GitHub https://github.com/xuebinqin/U-2-Net/issues/279#issuecomment-1007098556, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSGORNW266PES6TJQSEZADUUZIHRANCNFSM5LLIAJ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

-- Xuebin Qin PhD Department of Computing Science University of Alberta, Edmonton, AB, Canada Homepage: https://xuebinqin.github.io/

1benwu1 commented 1 year ago

i have a question here: the u2netp model(4.7M rather than 4.5M) i trained cannot be used, it said : RuntimeError: Error(s) in loading state_dict for U2NETP: