📅  最后修改于: 2022-03-11 14:47:06.351000             🧑  作者: Mango
# 第äºä¸ªç±»åæ¯ torch.cuda.FloatTensorï¼è¿æå³çå®æ¯å·²ç»ç§»å° GPU çå¼ éã
# å®æ³è·å¾ç±»å为 torch.FloatTensor çå¼ éï¼ä½æ¯æ²¡æ .cudaï¼å æ¤è¯¥å¼ éåºè¯¥å¨ CPU ä¸ã
# PyTorch åªè½å¯¹ä½äºç¸å设å¤ä¸çå¼ éè¿è¡è¿ç®ï¼å æ¤å¿
é¡»åæ¶ä½äº CPU æ GPU ä¸ãå¦æä½ è¦å¨ GPU
# ä¸è¿è¡ç½ç»ï¼ä¸å®è¦ä½¿ç¨ .to(device) å°æ¨¡ååææå¿
è¦å¼ éç§»å° GPU ä¸ï¼å
¶ä¸ device 为 "cuda" æ "cpu"ã
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = model.to(device) # the same model.cuda()
for images, labels in trainloader:
images, labels = images.to(device), labels.to(device)