close

 


試過,有效,一次經由過程。

2. 不利用多線程,也就是去掉num_workers 參數,或設定 num_workers=0。

(今朝還沒試過,因為我仍是想用多履行緒。)


文章出處: 網頁設計NetYea 網頁設計

參考文章
https://blog.csdn.net/u014546828/article/details/109235539

近從新調試一段pytorch 程式碼,之前的伺服器上完全沒問題,但換了一台機械,從新安裝了新版本的cuda, anaconda ,pytorch 等,之前的程式碼呈現各類版本不合適的問題。
問題:
現在說說這個問題。網頁設計運行pytorch 時泛起的環境以下:

  1. RuntimeError:
  2.         An attempt has been made to start a new process before the
  3.         current process has finished its bootstrapping phase.
  4.  
  5.         This probably means that you are not using fork to start your
  6.         child processes and you have forgotten to use the proper idiom
  7.         in the main module:
  8.  
  9.             if __name__ == '__main__':
  10.                 freeze_support()
  11.                 ...
  12.  
  13.         The "freeze_support()" line can be omitted if the program
  14.         is not going to be frozen to produce an executable.
複製代碼
  1. from ultralytics import YOLO
  2.  
  3. # Load a model
  4. model = YOLO("yolov8n.yaml")  # build a new model from scratch
  5. model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)
  6.  
  7. if __name__ == '__main__':
  8.     # Use the model
  9.     model.train(data="coco128.yaml", epochs=3)  # train the model
  10.     metrics = model.val()  # evaluate model performance on the validation set
  11.     results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image
  12.     path = model.export(format="onnx")  # export the model to ONNX format
複製代碼

網頁設計

Yolov8 PyTorch出現 An attempt ha



原因:
在網上查找結果,緣由是多曆程的緣由。具體可參考博文:Python 中的if __name__ == '__main__' 該若何理解。


解決方法:
既然是多執行緒的緣由,那麼可以從兩個角度解決問題:

1. 程式碼在運行 epoch 之前,加上    if __name__=='__main__'

arrow
arrow
    文章標籤
    網頁設計
    全站熱搜
    創作者介紹
    創作者 kamlesvidk 的頭像
    kamlesvidk

    湖口網頁設計

    kamlesvidk 發表在 痞客邦 留言(0) 人氣()