第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

if 語句的語法

if 語句的語法

慕運維8079593 2022-07-26 20:48:18
1.當我運行代碼時,我得到 else: print("no checkpoint found") 2.IndentationError: unindent does not match any external indentation level 3.我試圖修復(fù)它,但我不能  def Score(self):                  return sum(self.reward_window)/(len(self.reward_window)+1.)             def Save(self):                 torch.save({'state_dict' : self.model.state_dict(),                            'optimizer' : self.optimizer.state_dict,                            },'last_brain.pth')              def Load(self) :                  if os.path.isfile('last_brain.pth') :  # this is where i get the syntax error                    print("=> Loading last brain...")                     lastbrain = torch.load('last_brain.pth')                      self.model.load_state_dict(checkpoint['state_dict'])                      self.optimizer.load_state_dict(checkpoint['optimizer'])                     print ("done")                 else: print("no checkpoint found")
查看完整描述

2 回答

?
守著一只汪

TA貢獻1872條經(jīng)驗 獲得超4個贊

IMO [1],我認為問題的另一個原因是其他函數(shù)定義在與self. 我建議格式類似于:


def score(self):

  # code for score...

  # etc...


def save( self ):

  # code for save

  # etc...


def load(self):

  # code for load...

  # etc...

1:我沒有經(jīng)常使用 Python 來了解函數(shù)聲明方面的所有合法性,但是在大多數(shù)語言中,據(jù)我所知,在語言設(shè)置為代碼塊的內(nèi)容中不能有多個函數(shù)聲明(大括號在 C/C++/Java 中,在 Python 中使用縮進/冒號)。如果有人知道 Python 的例外或適當?shù)暮戏ㄐ裕堧S時在評論中直接告訴我)


查看完整回答
反對 回復(fù) 2022-07-26
?
慕婉清6462132

TA貢獻1804條經(jīng)驗 獲得超2個贊

您的代碼沒有正確縮進。應(yīng)該是這樣的


def Score(self):

            return sum(self.reward_window)/(len(self.reward_window)+1.) 


def Save(self): 

            torch.save({'state_dict' : self.model.state_dict(),

                        'optimizer' : self.optimizer.state_dict,

                        },'last_brain.pth')  


def Load(self) :  

            if os.path.isfile('last_brain.pth') :


                print("=> Loading last brain...") 

                lastbrain = torch.load('last_brain.pth')  

                self.model.load_state_dict(checkpoint['state_dict'])  

                self.optimizer.load_state_dict(checkpoint['optimizer']) 

                print ("done") 

            else: print("no checkpoint found")

根據(jù)您的縮進,您正在定義Save()and Load()inside Score(),這在 Python 中是不允許的。希望這能解決您的問題。


查看完整回答
反對 回復(fù) 2022-07-26
  • 2 回答
  • 0 關(guān)注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號