報錯:SyntaxError: unexpected character after line continuation character的解決方法


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 。

這里出現問題的原因是:

  第一行的換行符“\” 后面存在空格。當換行符后面存在空格時,程序就會報錯。

解決方法:

  很簡單,就把換行符“\” 后面的空格都刪掉,問題就解決了。

  也就是說,換行符后面是不允許再存在其他東西的。 包括 注釋#


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM