Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
d8b5beb0
Unverified
提交
d8b5beb0
authored
1月 28, 2022
作者:
Glenn Jocher
提交者:
GitHub
1月 28, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix2 `select_device()` for Multi-GPU (#6461)
* Fix2 select_device() for Multi-GPU * Cleanup * Cleanup * Simplify error message * Improve assert * Update torch_utils.py
上级
856d4e57
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
7 行删除
+7
-7
datasets.py
utils/datasets.py
+3
-3
torch_utils.py
utils/torch_utils.py
+4
-4
没有找到文件。
utils/datasets.py
浏览文件 @
d8b5beb0
...
...
@@ -29,13 +29,12 @@ from tqdm import tqdm
from
utils.augmentations
import
Albumentations
,
augment_hsv
,
copy_paste
,
letterbox
,
mixup
,
random_perspective
from
utils.general
import
(
LOGGER
,
NUM_THREADS
,
check_dataset
,
check_requirements
,
check_yaml
,
clean_str
,
segments2boxes
,
xyn2xy
,
xywh2xyxy
,
xywhn2xyxy
,
xyxy2xywhn
)
from
utils.torch_utils
import
device_count
,
torch_distributed_zero_first
from
utils.torch_utils
import
torch_distributed_zero_first
# Parameters
HELP_URL
=
'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
IMG_FORMATS
=
[
'bmp'
,
'dng'
,
'jpeg'
,
'jpg'
,
'mpo'
,
'png'
,
'tif'
,
'tiff'
,
'webp'
]
# include image suffixes
VID_FORMATS
=
[
'asf'
,
'avi'
,
'gif'
,
'm4v'
,
'mkv'
,
'mov'
,
'mp4'
,
'mpeg'
,
'mpg'
,
'wmv'
]
# include video suffixes
DEVICE_COUNT
=
max
(
device_count
(),
1
)
# number of CUDA devices
# Get orientation exif tag
for
orientation
in
ExifTags
.
TAGS
.
keys
():
...
...
@@ -110,7 +109,8 @@ def create_dataloader(path, imgsz, batch_size, stride, single_cls=False, hyp=Non
prefix
=
prefix
)
batch_size
=
min
(
batch_size
,
len
(
dataset
))
nw
=
min
([
os
.
cpu_count
()
//
DEVICE_COUNT
,
batch_size
if
batch_size
>
1
else
0
,
workers
])
# number of workers
nd
=
torch
.
cuda
.
device_count
()
# number of CUDA devices
nw
=
min
([
os
.
cpu_count
()
//
max
(
nd
,
1
),
batch_size
if
batch_size
>
1
else
0
,
workers
])
# number of workers
sampler
=
None
if
rank
==
-
1
else
distributed
.
DistributedSampler
(
dataset
,
shuffle
=
shuffle
)
loader
=
DataLoader
if
image_weights
else
InfiniteDataLoader
# only DataLoader allows for attribute updates
return
loader
(
dataset
,
...
...
utils/torch_utils.py
浏览文件 @
d8b5beb0
...
...
@@ -54,7 +54,8 @@ def git_describe(path=Path(__file__).parent): # path must be a directory
def
device_count
():
# Returns number of CUDA devices available. Safe version of torch.cuda.device_count().
# Returns number of CUDA devices available. Safe version of torch.cuda.device_count(). Only works on Linux.
assert
platform
.
system
()
==
'Linux'
,
'device_count() function only works on Linux'
try
:
cmd
=
'nvidia-smi -L | wc -l'
return
int
(
subprocess
.
run
(
cmd
,
shell
=
True
,
capture_output
=
True
,
check
=
True
)
.
stdout
.
decode
()
.
split
()[
-
1
])
...
...
@@ -70,10 +71,9 @@ def select_device(device='', batch_size=0, newline=True):
if
cpu
:
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'-1'
# force torch.cuda.is_available() = False
elif
device
:
# non-cpu device requested
nd
=
device_count
()
# number of CUDA devices
assert
nd
>
int
(
max
(
device
.
split
(
','
))),
f
'Invalid `--device {device}` request, valid devices are 0 - {nd - 1}'
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
device
# set environment variable - must be before assert is_available()
assert
torch
.
cuda
.
is_available
(),
'CUDA is not available, use `--device cpu` or do not pass a --device'
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)"
cuda
=
not
cpu
and
torch
.
cuda
.
is_available
()
if
cuda
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论