随笔 - 24, 文章 - 0, 评论 - 9, 阅读 - 61697
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
1
2
3
4
5
6
7
8
9
if opt.freeze_layers:                                                                                                                                                           
    output_layer_indices = [idx - 1 for idx, module in enumerate(model.module_list) \
                         if isinstance(module, YOLOLayer)]                                                                                                                     
    freeze_layer_indices = [x for x in range(len(model.module_list)) if\
                            (x not in output_layer_indices) and \
                            (x - 1 not in output_layer_indices)]                                                                                                                
    for idx in freeze_layer_indices:                                                                                                                                            
        for parameter in model.module_list[idx].parameters():                                                                                                                   
            parameter.requires_grad_(False)    

 注意:上面的代码表面看起来没有问题,但是报错:SyntaxError:unexpected character after line continuation character 。

这里出现问题的原因是:

  第一行的换行符“\” 后面存在空格。当换行符后面存在空格时,程序就会报错。

解决方法:

  很简单,就把换行符“\” 后面的空格都删掉,问题就解决了。

  也就是说,换行符后面是不允许再存在其他东西的。 包括 注释#

点击右上角即可分享
微信分享提示