import cv2 from PIL import Image from Nets.mobileNet import MobileNetV1 as Net from torch.utils.data import DataLoader from torchvision import transforms from torchvision.datasets import ImageFolder import os import torch PROJECT_PATH = os.path.abspath( os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir)) # 训练数据集 DATA_TRAIN = os.path.join(PROJECT_PATH, "MechineLearning/trainSet") # 模型保存地址 DATA_MODEL = os.path.join(PROJECT_PATH, "MechineLearning/model/alexNet.pth") DEVICE = torch.device("cuda") 将这段代码改成只用使用cpu的代码
时间: 2024-04-18 22:24:40 浏览: 151
Python2.x与3​​.x版本有哪些区别
import cv2
from PIL import Image
from Nets.mobileNet import MobileNetV1 as Net
from torch.utils.data import DataLoader
from torchvision import transforms
from torchvision.datasets import ImageFolder
import os
import torch
PROJECT_PATH = os.path.abspath(
os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir))
# 训练数据集
DATA_TRAIN = os.path.join(PROJECT_PATH, "MechineLearning/trainSet")
# 模型保存地址
DATA_MODEL = os.path.join(PROJECT_PATH, "MechineLearning/model/alexNet.pth")
DEVICE = torch.device("cpu") # 将设备改为cpu
注意,这只是将设备更改为CPU,可能需要根据你的代码的具体情况进行其他更改。
阅读全文