開発環境
Python 3.10.16
pytorch 2.5.1 py3.10_0 pytorch
↓↓↓Visual Studio Code↓↓↓
バージョン: 1.98.2
コミット: ddc367ed5c8936efe395cffeec279b04ffd7db78
日付: 2025-03-12T13:32:45.399Z
Electron: 34.2.0
ElectronBuildId: 11161602
Chromium: 132.0.6834.196
Node.js: 20.18.2
V8: 13.2.152.36-electron.0
OS: Darwin arm64 24.2.0
エラー内容
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[16], line 67
65 imgs = imgs.to(device).float()
66 # imgs = torch.squeeze(imgs)
---> 67 masks = masks.to(device).float()
68 masks = masks.view(imgs.shape[0], -1, 256, 256)
70 optimizer.zero_grad()
TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.
対処法
#Apple SiliconののGPUを使用する場合はmpsを指定する
device = torch.device("mps" if torch.mps.is_available() else "cpu")
masks.to(device).float() #これだとエラー
#↓
masks.float().to(device)