he-y / soft-filter-pruning

Soft Filter Pruning for Accelerating Deep Convolutional Neural Networks
https://arxiv.org/abs/1808.06866
374 stars 74 forks source link

state dict length is one of 102, 182, 267, 522? #18

Open simon5u opened 4 years ago

simon5u commented 4 years ago

Hi, may I know how to use the get_small_model.py? I tried to repeat the resnet50 pruning_train.py on imagenet and get the resnet50 checkpoint, then i load the model using get_small_model.py. I received the following error, False state dict because my resnet50 state dict size is 320 instead of 267. I also tried the resnet18 and my state dict size is 122 instead of 102? May I know how you get the 102 for resnet18 and 267 for resnet50? Thanks.

zhanghongruiupup commented 4 years ago

嗨,我可以知道如何使用get_small_model.py吗?我试图在imagenet上重复resnet50 pruning_train.py并获取resnet50检查点,然后使用get_small_model.py加载模型。我收到以下错误,错误状态字典,因为我的resnet50状态字典大小是320,而不是267。我也尝试过resnet18,状态字典大小是122,而不是102?我可以知道如何获得resnet18的102和resnet50的267吗?谢谢。

hello,I also encountered this mistake,Have you finished?

he-y commented 4 years ago

The reason might come from the version of PyTorch. For the new PyTorch version, the batch-norm layer has five state dicts, including 'bn1.weight', 'bn1.bias', 'bn1.running_mean', 'bn1.running_var', 'bn1.num_batches_tracked'. The old version does not has 'bn1.num_batches_tracked'. Please try the old version.

zhanghongruiupup commented 4 years ago

原因可能来自PyTorch的版本。 对于新的PyTorch版本,批处理规范层具有五个状态命令,包括“ bn1.weight”,“ bn1.bias”,“ bn1.running_mean”,“ bn1.running_var”,“ bn1.num_batches_tracked”。 旧版本没有'bn1.num_batches_tracked'。 请尝试旧版本。

You're right,Change 5 to 6,it work. now i trying turn .pt to .onnx , but Error occurred,It seems that the model structure is not instantiated。thank your code info:Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient

zhanghongruiupup commented 4 years ago

原因可能来自PyTorch的版本。 对于新的PyTorch版本,批处理规范层具有五个状态命令,包括“ bn1.weight”,“ bn1.bias”,“ bn1.running_mean”,“ bn1.running_var”,“ bn1.num_batches_tracked”。 旧版本没有'bn1.num_batches_tracked'。 请尝试旧版本。

You're right,Change 5 to 6,it work. now i trying turn .pt to .onnx , but Error occurred,It seems that the model structure is not instantiated。thank your code info:Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient

hi, i find turn .pt to .onnx error in this two code residual += self.bn_value.cuda() residual.indexadd(1, self.index.cuda(), out) Can you help me?thanks.

ghost commented 4 years ago

@zhanghongruiupup Hi, can you successfully run the get_small_model.py?

zhanghongruiupup commented 4 years ago

@zhanghongruiupup Hi, can you successfully run the get_small_model.py?

yes,make it

liwenwei123 commented 4 years ago

@zhanghongruiupup Hello! I encountered the same mistake with you! Can you share how did you edit the code to run the get_small_model.py successfully? Thank you so much.

Allhailankurgupta commented 4 years ago

I am facing the same problem

Allhailankurgupta commented 4 years ago

Also can you please tell how can I change the code for resnet20

liwenwei123 commented 4 years ago

@Allhailankurgupta Hello.You have to make sure that the version of your pytorch is PyTorch 0.3.1, just as the requirement in readme.And this code can run successfully without change.

Emily0219 commented 4 years ago

原因可能来自PyTorch的版本。 对于新的PyTorch版本,批处理规范层具有五个状态命令,包括“ bn1.weight”,“ bn1.bias”,“ bn1.running_mean”,“ bn1.running_var”,“ bn1.num_batches_tracked”。 旧版本没有'bn1.num_batches_tracked'。 请尝试旧版本。

You're right,Change 5 to 6,it work. now i trying turn .pt to .onnx , but Error occurred,It seems that the model structure is not instantiated。thank your code info:Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient

hi, i find turn .pt to .onnx error in this two code residual += self.bn_value.cuda() residual.indexadd(1, self.index.cuda(), out) Can you help me?thanks.

我也想知道这个bn_value是啥意思,为啥要相加啊

jianjiandandande commented 4 years ago

@zhanghongruiupup How much have you lowered Pytorch to? Too low will conflict with CUDA

curryJ commented 3 years ago

@Allhailankurgupta Hello.You have to make sure that the version of your pytorch is PyTorch 0.3.1, just as the requirement in readme.And this code can run successfully without change.

Hello,I run this code with pytorch==0.3.1 and torchvision==0.2.0,but I still have this issue about get_small_model.py. image Is this still a problem of vision?Thanks

image