无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網 會員登陸 & 注冊

yolov5修改dml運行代碼

2023-09-14 14:46 作者:pzqking  | 我要投稿

def select_device(device='', batch_size=0, newline=True):

? ? # device = None or 'cpu' or 0 or '0' or '0,1,2,3'

? ? s = f'YOLOv5 ?? {git_describe() or file_date()} Python-{platform.python_version()} torch-{torch.__version__} '

? ? device = str(device).strip().lower().replace('cuda:', '').replace('none', '')? # to string, 'cuda:0' to '0'

? ? dml = device == 'dml'#設置使用dml

? ? cpu = device == 'cpu'

? ? mps = device == 'mps'? # Apple Metal Performance Shaders (MPS)

? ? if cpu or mps or dml:

? ? ? ? os.environ['CUDA_VISIBLE_DEVICES'] = '-1'? # force torch.cuda.is_available() = False

? ? elif device:? # non-cpu device requested

? ? ? ? os.environ['CUDA_VISIBLE_DEVICES'] = device? # set environment variable - must be before assert is_available()

? ? ? ? assert torch.cuda.is_available() and torch.cuda.device_count() >= len(device.replace(',', '')), \

? ? ? ? ? ? f"Invalid CUDA '--device {device}' requested, use '--device cpu' or pass valid CUDA device(s)"

? ? if dml and torch_directml.is_available():

? ? ? ? devices=torch_directml.device(0)#啟用0號dml設備,在這可以更換使用的設備

? ? ? ? n=0

? ? ? ? s+=r"dml:"+str(torch_directml.device_name(0))

? ? ? ? arg=torch_directml.device(0)

? ? elif not cpu and not mps and torch.cuda.is_available():? # prefer GPU if available

? ? ? ? devices = device.split(',') if device else '0'? # range(torch.cuda.device_count())? # i.e. 0,1,6,7

? ? ? ? n = len(devices)? # device count

? ? ? ? if n > 1 and batch_size > 0:? # check batch_size is divisible by device_count

? ? ? ? ? ? assert batch_size % n == 0, f'batch-size {batch_size} not multiple of GPU count {n}'

? ? ? ? space = ' ' * (len(s) + 1)

? ? ? ? for i, d in enumerate(devices):

? ? ? ? ? ? p = torch.cuda.get_device_properties(i)

? ? ? ? ? ? s += f"{'' if i == 0 else space}CUDA:s0sssss00s ({p.name}, {p.total_memory / (1 << 20):.0f}MiB)\n"? # bytes to MB

? ? ? ? arg = 'cuda:0'

? ? elif mps and getattr(torch, 'has_mps', False) and torch.backends.mps.is_available():? # prefer MPS if available

? ? ? ? s += 'MPS\n'

? ? ? ? arg = 'mps'

? ? else:? # revert to CPU

? ? ? ? s += 'CPU\n'

? ? ? ? arg ="cpu"


? ? if not newline:

? ? ? ? s = s.rstrip()

? ? LOGGER.info(s)

? ??#print(torch.device(arg))

? ? return torch.device(arg)

#替換至utils文件夾下torch_utils.py中的select_device函數即可使用,

yolov5修改dml運行代碼的評論 (共 條)

分享到微博請遵守國家法律
泸溪县| 营口市| 益阳市| 大余县| 温州市| 西畴县| 万源市| 高阳县| 衡南县| 调兵山市| 西林县| 长武县| 古蔺县| 常宁市| 湟中县| 都昌县| 大关县| 娱乐| 永胜县| 麻城市| 通化市| 邯郸县| 盐源县| 墨脱县| 陇川县| 崇左市| 榆树市| 西昌市| 大丰市| 佳木斯市| 大洼县| 台湾省| 武乡县| 崇义县| 旅游| 资溪县| 辰溪县| 华宁县| 溧水县| 苗栗县| 泊头市|