Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
ff93284b
M
models
项目概览
PaddlePaddle
/
models
1 年多 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ff93284b
编写于
6月 11, 2019
作者:
S
SunGaofeng
提交者:
GitHub
6月 11, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify on nextvald, tsm and nonlocal to support v1.5 (#2386)
上级
700310a7
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
71 addition
and
25 deletion
+71
-25
PaddleCV/video/datareader/feature_reader.py
PaddleCV/video/datareader/feature_reader.py
+10
-12
PaddleCV/video/models/nextvlad/nextvlad.py
PaddleCV/video/models/nextvlad/nextvlad.py
+35
-6
PaddleCV/video/models/nonlocal_model/resnet_helper.py
PaddleCV/video/models/nonlocal_model/resnet_helper.py
+7
-0
PaddleCV/video/scripts/train/train_nextvlad.sh
PaddleCV/video/scripts/train/train_nextvlad.sh
+6
-0
PaddleCV/video/scripts/train/train_tsm.sh
PaddleCV/video/scripts/train/train_tsm.sh
+2
-0
PaddleCV/video/tools/train_utils.py
PaddleCV/video/tools/train_utils.py
+5
-3
PaddleCV/video/train.py
PaddleCV/video/train.py
+6
-4
未找到文件。
PaddleCV/video/datareader/feature_reader.py
浏览文件 @
ff93284b
...
...
@@ -77,18 +77,16 @@ class FeatureReader(DataReader):
rgb
=
rgb
[
0
:
nframes
,
:]
audio
=
audio
[
0
:
nframes
,
:]
rgb
=
dequantize
(
rgb
,
max_quantized_value
=
2.
,
min_quantized_value
=-
2.
)
audio
=
dequantize
(
audio
,
max_quantized_value
=
2
,
min_quantized_value
=-
2
)
if
self
.
name
==
'NEXTVLAD'
:
# add the effect of eigen values
eigen_file
=
self
.
eigen_file
eigen_val
=
np
.
sqrt
(
np
.
load
(
eigen_file
)
[:
1024
,
0
]).
astype
(
np
.
float32
)
eigen_val
=
eigen_val
+
1e-4
rgb
=
(
rgb
-
4.
/
512
)
*
eigen_val
if
self
.
name
!=
'NEXTVLAD'
:
rgb
=
dequantize
(
rgb
,
max_quantized_value
=
2.
,
min_quantized_value
=-
2.
)
audio
=
dequantize
(
audio
,
max_quantized_value
=
2
,
min_quantized_value
=-
2
)
if
self
.
name
==
'ATTENTIONCLUSTER'
:
sample_inds
=
generate_random_idx
(
rgb
.
shape
[
0
],
self
.
seg_num
)
...
...
PaddleCV/video/models/nextvlad/nextvlad.py
100755 → 100644
浏览文件 @
ff93284b
...
...
@@ -12,6 +12,8 @@
#See the License for the specific language governing permissions and
#limitations under the License.
import
numpy
as
np
import
paddle.fluid
as
fluid
from
paddle.fluid
import
ParamAttr
...
...
@@ -71,7 +73,7 @@ class NEXTVLAD(ModelBase):
shapes
=
[[
-
1
]
+
rgb_shape
,
[
-
1
]
+
audio_shape
,
[
-
1
]
+
label_shape
],
lod_levels
=
[
1
,
1
,
0
],
dtypes
=
[
'
float32'
,
'float32
'
,
'float32'
],
dtypes
=
[
'
uint8'
,
'uint8
'
,
'float32'
],
name
=
'train_py_reader'
if
self
.
is_training
else
'test_py_reader'
,
use_double_buffer
=
True
)
...
...
@@ -81,12 +83,12 @@ class NEXTVLAD(ModelBase):
rgb
=
fluid
.
layers
.
data
(
name
=
'train_rgb'
if
self
.
is_training
else
'test_rgb'
,
shape
=
rgb_shape
,
dtype
=
'
float32
'
,
dtype
=
'
uint8
'
,
lod_level
=
1
)
audio
=
fluid
.
layers
.
data
(
name
=
'train_audio'
if
self
.
is_training
else
'test_audio'
,
shape
=
audio_shape
,
dtype
=
'
float32
'
,
dtype
=
'
uint8
'
,
lod_level
=
1
)
if
self
.
mode
==
'infer'
:
label
=
None
...
...
@@ -115,6 +117,31 @@ class NEXTVLAD(ModelBase):
videomodel
=
nextvlad_model
.
NeXtVLADModel
()
rgb
=
self
.
feature_input
[
0
]
audio
=
self
.
feature_input
[
1
]
# move data processing from data reader to fluid to process on gpu
rgb
=
fluid
.
layers
.
cast
(
rgb
,
'float32'
)
audio
=
fluid
.
layers
.
cast
(
audio
,
'float32'
)
bias
=
-
2.
scale
=
4.
/
255
offset
=
4.
/
512
rgb
=
fluid
.
layers
.
scale
(
rgb
,
scale
=
scale
,
bias
=
bias
)
audio
=
fluid
.
layers
.
scale
(
audio
,
scale
=
scale
,
bias
=
bias
+
offset
)
eigen_value
=
np
.
sqrt
(
np
.
load
(
self
.
eigen_file
)[:
1024
,
0
])
eigen_value
=
(
eigen_value
+
1e-4
).
astype
(
np
.
float32
)
eigen_param
=
fluid
.
layers
.
create_parameter
(
shape
=
eigen_value
.
shape
,
dtype
=
'float32'
,
attr
=
fluid
.
ParamAttr
(
name
=
'eigen_param'
,
trainable
=
False
),
default_initializer
=
fluid
.
initializer
.
NumpyArrayInitializer
(
eigen_value
))
rgb
=
fluid
.
layers
.
elementwise_mul
(
rgb
,
eigen_param
)
rgb
.
stop_gradient
=
True
audio
.
stop_gradient
=
True
out
=
videomodel
.
create_model
(
rgb
,
audio
,
is_training
=
(
self
.
mode
==
'train'
),
**
model_args
)
self
.
logits
=
out
[
'logits'
]
...
...
@@ -146,10 +173,12 @@ class NEXTVLAD(ModelBase):
return
self
.
feature_input
if
self
.
mode
==
'infer'
else
self
.
feature_input
+
[
self
.
label_input
]
def
weights_info
(
self
):
return
(
'nextvlad_youtube8m'
,
'https://paddlemodels.bj.bcebos.com/video_classification/nextvlad_youtube8m.tar.gz'
)
return
(
'nextvlad_youtube8m'
,
'https://paddlemodels.bj.bcebos.com/video_classification/nextvlad_youtube8m.tar.gz'
)
def
get_learning_rate_decay_list
(
base_learning_rate
,
decay
,
max_iter
,
...
...
PaddleCV/video/models/nonlocal_model/resnet_helper.py
浏览文件 @
ff93284b
...
...
@@ -264,6 +264,13 @@ def res_stage_nonlocal(block_fn,
for
idx
in
range
(
num_blocks
):
block_prefix
=
'{}{}'
.
format
(
prefix
,
chr
(
idx
+
97
))
if
cfg
.
MODEL
.
depth
==
101
:
if
num_blocks
==
23
:
if
idx
==
0
:
block_prefix
=
'{}{}'
.
format
(
prefix
,
chr
(
97
))
else
:
block_prefix
=
'{}{}{}'
.
format
(
prefix
,
'b'
,
idx
)
block_stride
=
2
if
((
idx
==
0
)
and
(
stride
==
2
))
else
1
blob_in
=
_generic_residual_block_3d
(
blob_in
,
...
...
PaddleCV/video/scripts/train/train_nextvlad.sh
浏览文件 @
ff93284b
# activate eager gc to reduce memory use
#export FLAGS_fraction_of_gpu_memory_to_use=1.0
#export FLAGS_fast_eager_deletion_mode=1
#export FLAGS_eager_delete_tensor_gb=0.0
#export FLAGS_limit_of_tmp_allocation=0
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3
python train.py
--model_name
=
"NEXTVLAD"
--config
=
./configs/nextvlad.txt
--epoch
=
6
\
--valid_interval
=
1
--log_interval
=
10
PaddleCV/video/scripts/train/train_tsm.sh
浏览文件 @
ff93284b
...
...
@@ -4,6 +4,8 @@ export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
export
FLAGS_fast_eager_deletion_mode
=
1
export
FLAGS_eager_delete_tensor_gb
=
0.0
export
FLAGS_fraction_of_gpu_memory_to_use
=
0.98
#export FLAGS_limit_of_tmp_allocation=0
#export FLAGS_conv_workspace_size_limit=1024
python train.py
--model_name
=
"TSM"
--config
=
./configs/tsm.txt
--epoch
=
65
\
--valid_interval
=
1
--log_interval
=
10
PaddleCV/video/tools/train_utils.py
浏览文件 @
ff93284b
...
...
@@ -101,7 +101,7 @@ def train_without_pyreader(exe, train_prog, train_exe, train_reader, train_feede
info
=
'[TRAIN] Epoch {}, iter {} '
.
format
(
epoch
,
train_iter
))
train_iter
+=
1
logger
.
info
(
'[TRAIN] Epoch {} training finished, average time: {}'
.
format
(
epoch
,
np
.
mean
(
epoch_periods
)))
format
(
epoch
,
np
.
mean
(
epoch_periods
[
1
:]
)))
save_model
(
exe
,
train_prog
,
save_dir
,
save_model_name
,
"_epoch{}"
.
format
(
epoch
))
if
test_exe
and
valid_interval
>
0
and
(
epoch
+
1
...
...
@@ -144,7 +144,7 @@ def train_with_pyreader(exe, train_prog, train_exe, train_pyreader, \
except
fluid
.
core
.
EOFException
:
# eval here
logger
.
info
(
'[TRAIN] Epoch {} training finished, average time: {}'
.
format
(
epoch
,
np
.
mean
(
epoch_periods
)))
format
(
epoch
,
np
.
mean
(
epoch_periods
[
1
:]
)))
save_model
(
exe
,
train_prog
,
save_dir
,
save_model_name
,
"_epoch{}"
.
format
(
epoch
))
if
test_exe
and
valid_interval
>
0
and
(
epoch
+
1
...
...
@@ -159,7 +159,9 @@ def train_with_pyreader(exe, train_prog, train_exe, train_pyreader, \
cards
=
os
.
environ
.
get
(
'CUDA_VISIBLE_DEVICES'
)
gpu_num
=
len
(
cards
.
split
(
","
))
print
(
"kpis
\t
train_cost_card{}
\t
{}"
.
format
(
gpu_num
,
train_loss
))
print
(
"kpis
\t
train_speed_card{}
\t
{}"
.
format
(
gpu_num
,
np
.
mean
(
epoch_periods
)))
print
(
"kpis
\t
train_speed_card{}
\t
{}"
.
format
(
gpu_num
,
np
.
mean
(
epoch_periods
)))
def
save_model
(
exe
,
program
,
save_dir
,
model_name
,
postfix
=
None
):
model_path
=
os
.
path
.
join
(
save_dir
,
model_name
+
postfix
)
...
...
PaddleCV/video/train.py
浏览文件 @
ff93284b
...
...
@@ -140,9 +140,6 @@ def train(args):
optimizer
.
minimize
(
train_loss
)
train_pyreader
=
train_model
.
pyreader
()
if
not
args
.
no_memory_optimize
:
fluid
.
memory_optimize
(
train_prog
)
valid_prog
=
fluid
.
Program
()
with
fluid
.
program_guard
(
valid_prog
,
startup
):
with
fluid
.
unique_name
.
guard
():
...
...
@@ -176,10 +173,15 @@ def train(args):
if
pretrain
:
train_model
.
load_pretrain_params
(
exe
,
pretrain
,
train_prog
,
place
)
build_strategy
=
fluid
.
BuildStrategy
()
build_strategy
.
enable_inplace
=
True
#build_strategy.memory_optimize = True
train_exe
=
fluid
.
ParallelExecutor
(
use_cuda
=
args
.
use_gpu
,
loss_name
=
train_loss
.
name
,
main_program
=
train_prog
)
main_program
=
train_prog
,
build_strategy
=
build_strategy
)
valid_exe
=
fluid
.
ParallelExecutor
(
use_cuda
=
args
.
use_gpu
,
share_vars_from
=
train_exe
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录