Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
f926be0a
M
Models
项目概览
曾经的那一瞬间
/
Models
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f926be0a
编写于
12月 04, 2019
作者:
A
A. Unique TensorFlower
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved set_gpu_thread_mode_and_count from vision/image_classification/common.py to
utils/misc/keras_utils PiperOrigin-RevId: 283885102
上级
91a1ce9b
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
50 addition
and
38 deletion
+50
-38
official/utils/misc/keras_utils.py
official/utils/misc/keras_utils.py
+40
-9
official/vision/image_classification/common.py
official/vision/image_classification/common.py
+0
-27
official/vision/image_classification/resnet_cifar_main.py
official/vision/image_classification/resnet_cifar_main.py
+5
-1
official/vision/image_classification/resnet_imagenet_main.py
official/vision/image_classification/resnet_imagenet_main.py
+5
-1
未找到文件。
official/utils/misc/keras_utils.py
浏览文件 @
f926be0a
...
...
@@ -18,8 +18,11 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
multiprocessing
import
os
import
time
from
absl
import
logging
import
tensorflow
as
tf
from
tensorflow.core.protobuf
import
rewriter_config_pb2
from
tensorflow.python
import
tf2
...
...
@@ -79,18 +82,18 @@ class TimeHistory(tf.keras.callbacks.Callback):
elapsed_time
=
timestamp
-
self
.
start_time
examples_per_second
=
(
self
.
batch_size
*
self
.
log_steps
)
/
elapsed_time
self
.
timestamp_log
.
append
(
BatchTimestamp
(
self
.
global_steps
,
timestamp
))
tf
.
compat
.
v1
.
logging
.
info
(
logging
.
info
(
"BenchmarkMetric: {'global step':%d, 'time_taken': %f,"
"'examples_per_second': %f}"
%
(
self
.
global_steps
,
elapsed_time
,
examples_per_second
)
)
"'examples_per_second': %f}"
,
self
.
global_steps
,
elapsed_time
,
examples_per_second
)
self
.
start_time
=
timestamp
def
on_epoch_end
(
self
,
epoch
,
logs
=
None
):
epoch_run_time
=
time
.
time
()
-
self
.
epoch_start
self
.
epoch_runtime_log
.
append
(
epoch_run_time
)
tf
.
compat
.
v1
.
logging
.
info
(
"BenchmarkMetric: {'epoch':%d, 'time_taken': %f}"
%
(
epoch
,
epoch_run_time
)
)
logging
.
info
(
"BenchmarkMetric: {'epoch':%d, 'time_taken': %f}"
,
epoch
,
epoch_run_time
)
def
get_profiler_callback
(
model_dir
,
profile_steps
,
enable_tensorboard
,
...
...
@@ -110,7 +113,7 @@ def get_profiler_callback(model_dir, profile_steps, enable_tensorboard,
if
start_step
<
0
or
start_step
>
stop_step
:
raise
ValueError
(
profile_steps_error_message
)
if
enable_tensorboard
:
tf
.
compat
.
v1
.
logging
.
warn
(
logging
.
warning
(
'Both TensorBoard and profiler callbacks are used. Note that the '
'TensorBoard callback profiles the 2nd step (unless otherwise '
'specified). Please make sure the steps profiled by the two callbacks '
...
...
@@ -143,14 +146,14 @@ class ProfilerCallback(tf.keras.callbacks.Callback):
if
batch
==
self
.
start_step_in_epoch
and
self
.
should_start
:
self
.
should_start
=
False
profiler
.
start
()
tf
.
compat
.
v1
.
logging
.
info
(
'Profiler started at Step %s'
,
self
.
start_step
)
logging
.
info
(
'Profiler started at Step %s'
,
self
.
start_step
)
def
on_batch_end
(
self
,
batch
,
logs
=
None
):
if
batch
==
self
.
stop_step_in_epoch
and
self
.
should_stop
:
self
.
should_stop
=
False
results
=
profiler
.
stop
()
profiler
.
save
(
self
.
log_dir
,
results
)
tf
.
compat
.
v1
.
logging
.
info
(
logging
.
info
(
'Profiler saved profiles for steps between %s and %s to %s'
,
self
.
start_step
,
self
.
stop_step
,
self
.
log_dir
)
...
...
@@ -197,3 +200,31 @@ def set_config_v2(enable_xla=False):
def
is_v2_0
():
"""Returns true if using tf 2.0."""
return
tf2
.
enabled
()
def
set_gpu_thread_mode_and_count
(
gpu_thread_mode
,
datasets_num_private_threads
,
num_gpus
,
per_gpu_thread_count
):
"""Set GPU thread mode and count, and adjust dataset threads count."""
cpu_count
=
multiprocessing
.
cpu_count
()
logging
.
info
(
'Logical CPU cores: %s'
,
cpu_count
)
# Allocate private thread pool for each GPU to schedule and launch kernels
per_gpu_thread_count
=
per_gpu_thread_count
or
2
os
.
environ
[
'TF_GPU_THREAD_MODE'
]
=
gpu_thread_mode
os
.
environ
[
'TF_GPU_THREAD_COUNT'
]
=
str
(
per_gpu_thread_count
)
logging
.
info
(
'TF_GPU_THREAD_COUNT: %s'
,
os
.
environ
[
'TF_GPU_THREAD_COUNT'
])
logging
.
info
(
'TF_GPU_THREAD_MODE: %s'
,
os
.
environ
[
'TF_GPU_THREAD_MODE'
])
# Limit data preprocessing threadpool to CPU cores minus number of total GPU
# private threads and memory copy threads.
total_gpu_thread_count
=
per_gpu_thread_count
*
num_gpus
num_runtime_threads
=
num_gpus
if
not
datasets_num_private_threads
:
datasets_num_private_threads
=
min
(
cpu_count
-
total_gpu_thread_count
-
num_runtime_threads
,
num_gpus
*
8
)
logging
.
info
(
'Set datasets_num_private_threads to %s'
,
datasets_num_private_threads
)
official/vision/image_classification/common.py
浏览文件 @
f926be0a
...
...
@@ -17,7 +17,6 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
multiprocessing
import
os
from
absl
import
flags
...
...
@@ -174,32 +173,6 @@ class PiecewiseConstantDecayWithWarmup(
}
def
set_gpu_thread_mode_and_count
(
flags_obj
):
"""Set GPU thread mode and count, and adjust dataset threads count."""
cpu_count
=
multiprocessing
.
cpu_count
()
tf
.
compat
.
v1
.
logging
.
info
(
'Logical CPU cores: %s'
,
cpu_count
)
# Allocate private thread pool for each GPU to schedule and launch kernels
per_gpu_thread_count
=
flags_obj
.
per_gpu_thread_count
or
2
os
.
environ
[
'TF_GPU_THREAD_MODE'
]
=
flags_obj
.
tf_gpu_thread_mode
os
.
environ
[
'TF_GPU_THREAD_COUNT'
]
=
str
(
per_gpu_thread_count
)
tf
.
compat
.
v1
.
logging
.
info
(
'TF_GPU_THREAD_COUNT: %s'
,
os
.
environ
[
'TF_GPU_THREAD_COUNT'
])
tf
.
compat
.
v1
.
logging
.
info
(
'TF_GPU_THREAD_MODE: %s'
,
os
.
environ
[
'TF_GPU_THREAD_MODE'
])
# Limit data preprocessing threadpool to CPU cores minus number of total GPU
# private threads and memory copy threads.
total_gpu_thread_count
=
per_gpu_thread_count
*
flags_obj
.
num_gpus
num_runtime_threads
=
flags_obj
.
num_gpus
if
not
flags_obj
.
datasets_num_private_threads
:
flags_obj
.
datasets_num_private_threads
=
min
(
cpu_count
-
total_gpu_thread_count
-
num_runtime_threads
,
flags_obj
.
num_gpus
*
8
)
tf
.
compat
.
v1
.
logging
.
info
(
'Set datasets_num_private_threads to %s'
,
flags_obj
.
datasets_num_private_threads
)
def
get_optimizer
(
learning_rate
=
0.1
):
"""Returns optimizer to use."""
# The learning_rate is overwritten at the beginning of each step by callback.
...
...
official/vision/image_classification/resnet_cifar_main.py
浏览文件 @
f926be0a
...
...
@@ -83,7 +83,11 @@ def run(flags_obj):
# Execute flag override logic for better model performance
if
flags_obj
.
tf_gpu_thread_mode
:
common
.
set_gpu_thread_mode_and_count
(
flags_obj
)
keras_utils
.
set_gpu_thread_mode_and_count
(
per_gpu_thread_count
=
flags_obj
.
per_gpu_thread_count
,
gpu_thread_mode
=
flags_obj
.
tf_gpu_thread_mode
,
num_gpus
=
flags_obj
.
num_gpus
,
datasets_num_private_threads
=
flags_obj
.
datasets_num_private_threads
)
common
.
set_cudnn_batchnorm_mode
()
dtype
=
flags_core
.
get_tf_dtype
(
flags_obj
)
...
...
official/vision/image_classification/resnet_imagenet_main.py
浏览文件 @
f926be0a
...
...
@@ -54,7 +54,11 @@ def run(flags_obj):
# Execute flag override logic for better model performance
if
flags_obj
.
tf_gpu_thread_mode
:
common
.
set_gpu_thread_mode_and_count
(
flags_obj
)
keras_utils
.
set_gpu_thread_mode_and_count
(
per_gpu_thread_count
=
flags_obj
.
per_gpu_thread_count
,
gpu_thread_mode
=
flags_obj
.
tf_gpu_thread_mode
,
num_gpus
=
flags_obj
.
num_gpus
,
datasets_num_private_threads
=
flags_obj
.
datasets_num_private_threads
)
common
.
set_cudnn_batchnorm_mode
()
dtype
=
flags_core
.
get_tf_dtype
(
flags_obj
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录