Tencent / PocketFlow

An Automatic Model Compression (AutoMC) framework for developing smaller and faster AI applications.
https://pocketflow.github.io
Other
2.78k stars 490 forks source link

ChannelPrunedLearner on MobileNetV1 #160

Open askingbot opened 5 years ago

askingbot commented 5 years ago

First of all, thanks for the open source on AutoMC. I really appreciate it.

When I tried to run ChannelPrunedLearner on MobileNetV1 using the following command

./scripts/run_local.sh nets/mobilenet_at_ilsvrc12_run.py --learner channel --data_dir_local DATA_DIR

and the checkpoint provided here, I got the error

Traceback (most recent call last):
  File "main.py", line 69, in <module>
    tf.app.run()
  File "/home/windqaq/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "main.py", line 55, in main
    learner.train()
  File "/home/windqaq/PocketFlow/learners/channel_pruning/learner.py", line 140, in train
    self.__prune_and_finetune_auto()
  File "/home/windqaq/PocketFlow/learners/channel_pruning/learner.py", line 609, in __prune_and_finetune_auto
    done = self.__prune_list_layers(queue, [FLAGS.cp_list_group])
  File "/home/windqaq/PocketFlow/learners/channel_pruning/learner.py", line 550, in __prune_list_layers
    done = self.__prune_n_layers(p, queue)
  File "/home/windqaq/PocketFlow/learners/channel_pruning/learner.py", line 565, in __prune_n_layers
    _, _, done, _ = self.pruner.compress(ratio)
  File "/home/windqaq/PocketFlow/learners/channel_pruning/channel_pruner.py", line 754, in compress
    self.max_strategy_dict[self._model.fathers[conv_op.name]][1] = c_ratio
KeyError: 'model/MobilenetV1/MobilenetV1/Conv2d_1_depthwise/depthwise'

My tensorflow version is tensorflow-gpu 1.11.0 which matches the one in requirements.txt (>= 1.10.0). I am wondering whether the checkpoint is outdated or there is something wrong with my setting. If there is anything I can do, please let me know. I am looking forward to your response. Thank you!

jiaxiang-wu commented 5 years ago

@askingbot Hi, I cannot reproduce your issue. ChannelPrunedLearner works as expected in my experiments. Can you post the md5sum code of your downloaded pre-trained model?

sunzhe09 commented 5 years ago

I met the same problem by myselfmodel: INFO:tensorflow:Channel pruning the model/MobilenetV2/Conv_1/Conv2D layer, the pruning rate is 0.265625 INFO:tensorflow:Actural preserv ratio: 0.265625 INFO:tensorflow:state is [[1. 0.5 1. 0.01785714 0.01785714 0.5 0.14138546 0.00255102]] INFO:tensorflow:RL choosed preserv ratio: [[0.26414657]] INFO:tensorflow:preserve ratio before constraint 1 INFO:tensorflow:preserve ratio after constraint 1 Traceback (most recent call last): File "main.py", line 53, in tf.app.run() File "/home/trainer/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "main.py", line 39, in main learner.train() File "/data/raid/PocketFlow/learners/channel_pruning/learner.py", line 140, in train self.prune_and_finetune_auto() File "/data/raid/PocketFlow/learners/channel_pruning/learner.py", line 595, in prune_and_finetune_auto self.prune_rl() File "/data/raid/PocketFlow/learners/channel_pruning/learner.py", line 658, in prune_rl state_next, acc_flops, done, real_action = self.pruner.compress(action) File "/data/raid/PocketFlow/learners/channel_pruning/channel_pruner.py", line 754, in compress self.max_strategy_dict[self._model.fathers[conv_op.name]][1] = c_ratio KeyError: 'model/MobilenetV2/Logits/SeparableConv2d/depthwise'

askingbot commented 5 years ago

@jiaxiang-wu here it is. screenshot from 2018-12-26 14-37-45

askingbot commented 5 years ago

Also, here is the more detailed log. Note that it occurred after running for half a day.

INFO:tensorflow:max_strategy_dict
 {'model/MobilenetV1/MobilenetV1/Conv2d_9_pointwise/Conv2D': [0.26413688858352186, 0.26413688858352186], 'model/MobilenetV1/MobilenetV1/Conv2d_2_pointwise/Conv
2D': [0.26413688858352186, 0.26413688858352186], 'model/MobilenetV1/MobilenetV1/Conv2d_4_pointwise/Conv2D': [0.26413688858352186, 0.26413688858352186], 'model/
MobilenetV1/MobilenetV1/Conv2d_0/Conv2D': [1.0, 0.26413688858352186], 'model/MobilenetV1/MobilenetV1/Conv2d_13_pointwise/Conv2D': [0.26413688858352186, 1.0], '
model/MobilenetV1/MobilenetV1/Conv2d_6_pointwise/Conv2D': [0.26413688858352186, 0.26413688858352186], 'model/MobilenetV1/MobilenetV1/Conv2d_12_pointwise/Conv2D
': [0.26413688858352186, 0.26413688858352186], 'model/MobilenetV1/MobilenetV1/Conv2d_8_pointwise/Conv2D': [0.26413688858352186, 0.26413688858352186], 'model/Mo
bilenetV1/MobilenetV1/Conv2d_7_pointwise/Conv2D': [0.26413688858352186, 0.26413688858352186], 'model/MobilenetV1/MobilenetV1/Conv2d_3_pointwise/Conv2D': [0.264
13688858352186, 0.26413688858352186], 'model/MobilenetV1/MobilenetV1/Conv2d_11_pointwise/Conv2D': [0.26413688858352186, 0.26413688858352186], 'model/MobilenetV
1/MobilenetV1/Conv2d_5_pointwise/Conv2D': [0.26413688858352186, 0.26413688858352186], 'model/MobilenetV1/MobilenetV1/Conv2d_1_pointwise/Conv2D': [0.26413688858
352186, 0.26413688858352186], 'model/MobilenetV1/Logits/Conv2d_1c_1x1/Conv2D': [1.0, 1.0], 'model/MobilenetV1/MobilenetV1/Conv2d_10_pointwise/Conv2D': [0.26413
688858352186, 0.26413688858352186]}
INFO:tensorflow:best split ratio is: [1.0, 1.0, 0.265625, 0.265625, 0.2578125, 0.265625, 0.26953125, 0.267578125, 0.2734375, 0.26953125, 0.265625, 0.26171875, 
1.0, 1.0, 1.0]
INFO:tensorflow:accuracy: 0.08958332985639572
INFO:tensorflow:acc_top1: 0.02291666716337204
INFO:tensorflow:acc_top5: 0.08958332985639572
INFO:tensorflow:loss: 3056118.5
INFO:tensorflow:preserve ratio before constraint 1.0
INFO:tensorflow:preserve ratio after constraint 1.0
INFO:tensorflow:Channel pruning the model/MobilenetV1/MobilenetV1/Conv2d_0/Conv2D layer,       the pruning rate is 1.0
INFO:tensorflow:preserve ratio before constraint 1.0
INFO:tensorflow:max_reduced_flops 113014517.2512835
INFO:tensorflow:desired_preserce 551355392.0
INFO:tensorflow:this flops 13571412.502084395
INFO:tensorflow:recommand action 33.298839540938935
INFO:tensorflow:preserve ratio after constraint 1.0
Traceback (most recent call last):
  File "main.py", line 69, in <module>
    tf.app.run()
  File "/home/windqaq/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "main.py", line 55, in main
    learner.train()
  File "/home/windqaq/PocketFlow/learners/channel_pruning/learner.py", line 140, in train
    self.__prune_and_finetune_auto()
  File "/home/windqaq/PocketFlow/learners/channel_pruning/learner.py", line 609, in __prune_and_finetune_auto
    done = self.__prune_list_layers(queue, [FLAGS.cp_list_group])
  File "/home/windqaq/PocketFlow/learners/channel_pruning/learner.py", line 550, in __prune_list_layers
    done = self.__prune_n_layers(p, queue)
  File "/home/windqaq/PocketFlow/learners/channel_pruning/learner.py", line 565, in __prune_n_layers
    _, _, done, _ = self.pruner.compress(ratio)
  File "/home/windqaq/PocketFlow/learners/channel_pruning/channel_pruner.py", line 754, in compress
    self.max_strategy_dict[self._model.fathers[conv_op.name]][1] = c_ratio
KeyError: 'model/MobilenetV1/MobilenetV1/Conv2d_1_depthwise/depthwise'
jiaxiang-wu commented 5 years ago

@askingbot Thanks for your information.

LJCLWS commented 3 years ago

hi! I meet the same problem, I want to know if it have been solved. I will be grateful if you can reply to me as soon as possible