最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

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運行代碼的評論 (共 條)

分享到微博請遵守國家法律
浙江省| 庆阳市| 托里县| 沈丘县| 方城县| 文登市| 新干县| 广饶县| 南江县| 宝坻区| 大宁县| 绩溪县| 屏山县| 论坛| 荔浦县| 黄山市| 万宁市| 兴海县| 昌吉市| 柳林县| 博客| 永善县| 元朗区| 龙陵县| 望都县| 交城县| 南澳县| 灵宝市| 大新县| 简阳市| 永寿县| 盐亭县| 邵东县| 若羌县| 渭南市| 德令哈市| 遂溪县| 通州市| 东丰县| 阿拉尔市| 南华县|