Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
18e1cf04
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
18e1cf04
编写于
9月 16, 2021
作者:
D
dongshuilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix pact bug for circlemargin arcmargin cosmargin
上级
1abbc826
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
461 addition
and
40 deletion
+461
-40
.gitignore
.gitignore
+2
-1
ppcls/arch/gears/arcmargin.py
ppcls/arch/gears/arcmargin.py
+7
-12
ppcls/arch/gears/circlemargin.py
ppcls/arch/gears/circlemargin.py
+8
-9
ppcls/arch/gears/cosmargin.py
ppcls/arch/gears/cosmargin.py
+7
-11
ppcls/configs/Vehicle/ResNet50.yaml
ppcls/configs/Vehicle/ResNet50.yaml
+2
-5
ppcls/configs/Vehicle/ResNet50_ReID.yaml
ppcls/configs/Vehicle/ResNet50_ReID.yaml
+1
-1
ppcls/configs/slim/ResNet50_vehicle_cls_prune.yaml
ppcls/configs/slim/ResNet50_vehicle_cls_prune.yaml
+136
-0
ppcls/configs/slim/ResNet50_vehicle_cls_quantization.yaml
ppcls/configs/slim/ResNet50_vehicle_cls_quantization.yaml
+135
-0
ppcls/configs/slim/ResNet50_vehicle_reid_prune.yaml
ppcls/configs/slim/ResNet50_vehicle_reid_prune.yaml
+1
-1
ppcls/configs/slim/ResNet50_vehicle_reid_quantization.yaml
ppcls/configs/slim/ResNet50_vehicle_reid_quantization.yaml
+162
-0
未找到文件。
.gitignore
浏览文件 @
18e1cf04
...
...
@@ -3,10 +3,11 @@ __pycache__/
*.sw*
*/workerlog*
checkpoints/
output/
output
*
/
pretrained/
.ipynb_checkpoints/
*.ipynb*
_build/
build/
log/
nohup.out
ppcls/arch/gears/arcmargin.py
浏览文件 @
18e1cf04
...
...
@@ -24,30 +24,25 @@ class ArcMargin(nn.Layer):
margin
=
0.5
,
scale
=
80.0
,
easy_margin
=
False
):
super
(
ArcMargin
,
self
).
__init__
()
super
().
__init__
()
self
.
embedding_size
=
embedding_size
self
.
class_num
=
class_num
self
.
margin
=
margin
self
.
scale
=
scale
self
.
easy_margin
=
easy_margin
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
paddle
.
nn
.
initializer
.
XavierNormal
())
self
.
fc
=
nn
.
Linear
(
self
.
embedding_size
,
self
.
class_num
,
weight_attr
=
weight_attr
,
bias_attr
=
False
)
self
.
weight
=
self
.
create_parameter
(
shape
=
[
self
.
embedding_size
,
self
.
class_num
],
is_bias
=
False
,
default_initializer
=
paddle
.
nn
.
initializer
.
XavierNormal
())
def
forward
(
self
,
input
,
label
=
None
):
input_norm
=
paddle
.
sqrt
(
paddle
.
sum
(
paddle
.
square
(
input
),
axis
=
1
,
keepdim
=
True
))
input
=
paddle
.
divide
(
input
,
input_norm
)
weight
=
self
.
fc
.
weight
weight_norm
=
paddle
.
sqrt
(
paddle
.
sum
(
paddle
.
square
(
weight
),
axis
=
0
,
keepdim
=
True
))
weight
=
paddle
.
divide
(
weight
,
weight_norm
)
paddle
.
sum
(
paddle
.
square
(
self
.
weight
),
axis
=
0
,
keepdim
=
True
))
weight
=
paddle
.
divide
(
self
.
weight
,
weight_norm
)
cos
=
paddle
.
matmul
(
input
,
weight
)
if
not
self
.
training
or
label
is
None
:
...
...
ppcls/arch/gears/circlemargin.py
浏览文件 @
18e1cf04
...
...
@@ -26,20 +26,19 @@ class CircleMargin(nn.Layer):
self
.
embedding_size
=
embedding_size
self
.
class_num
=
class_num
weight_attr
=
paddle
.
ParamAtt
r
(
initializer
=
paddle
.
nn
.
initializer
.
XavierNormal
())
self
.
fc
=
paddle
.
nn
.
Linear
(
self
.
embedding_size
,
self
.
class_num
,
weight_attr
=
weight_attr
)
self
.
weight
=
self
.
create_paramete
r
(
shape
=
[
self
.
embedding_size
,
self
.
class_num
],
is_bias
=
False
,
default_initializer
=
paddle
.
nn
.
initializer
.
XavierNormal
()
)
def
forward
(
self
,
input
,
label
):
feat_norm
=
paddle
.
sqrt
(
paddle
.
sum
(
paddle
.
square
(
input
),
axis
=
1
,
keepdim
=
True
))
input
=
paddle
.
divide
(
input
,
feat_norm
)
weight
=
self
.
fc
.
weight
weight_norm
=
paddle
.
sqrt
(
paddle
.
sum
(
paddle
.
square
(
weight
),
axis
=
0
,
keepdim
=
True
))
weight
=
paddle
.
divide
(
weight
,
weight_norm
)
paddle
.
sum
(
paddle
.
square
(
self
.
weight
),
axis
=
0
,
keepdim
=
True
))
weight
=
paddle
.
divide
(
self
.
weight
,
weight_norm
)
logits
=
paddle
.
matmul
(
input
,
weight
)
if
not
self
.
training
or
label
is
None
:
...
...
ppcls/arch/gears/cosmargin.py
浏览文件 @
18e1cf04
...
...
@@ -25,13 +25,10 @@ class CosMargin(paddle.nn.Layer):
self
.
embedding_size
=
embedding_size
self
.
class_num
=
class_num
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
paddle
.
nn
.
initializer
.
XavierNormal
())
self
.
fc
=
nn
.
Linear
(
self
.
embedding_size
,
self
.
class_num
,
weight_attr
=
weight_attr
,
bias_attr
=
False
)
self
.
weight
=
self
.
create_parameter
(
shape
=
[
self
.
embedding_size
,
self
.
class_num
],
is_bias
=
False
,
default_initializer
=
paddle
.
nn
.
initializer
.
XavierNormal
())
def
forward
(
self
,
input
,
label
):
label
.
stop_gradient
=
True
...
...
@@ -40,10 +37,9 @@ class CosMargin(paddle.nn.Layer):
paddle
.
sum
(
paddle
.
square
(
input
),
axis
=
1
,
keepdim
=
True
))
input
=
paddle
.
divide
(
input
,
input_norm
)
weight
=
self
.
fc
.
weight
weight_norm
=
paddle
.
sqrt
(
paddle
.
sum
(
paddle
.
square
(
weight
),
axis
=
0
,
keepdim
=
True
))
weight
=
paddle
.
divide
(
weight
,
weight_norm
)
paddle
.
sum
(
paddle
.
square
(
self
.
weight
),
axis
=
0
,
keepdim
=
True
))
weight
=
paddle
.
divide
(
self
.
weight
,
weight_norm
)
cos
=
paddle
.
matmul
(
input
,
weight
)
if
not
self
.
training
or
label
is
None
:
...
...
ppcls/configs/Vehicle/ResNet50.yaml
浏览文件 @
18e1cf04
...
...
@@ -2,7 +2,7 @@
Global
:
checkpoints
:
null
pretrained_model
:
null
output_dir
:
"
./output/"
output_dir
:
"
./output
_vehicle_cls
/"
device
:
"
gpu"
save_interval
:
1
eval_during_train
:
True
...
...
@@ -51,11 +51,8 @@ Optimizer:
name
:
Momentum
momentum
:
0.9
lr
:
name
:
MultiStepDecay
name
:
Cosine
learning_rate
:
0.01
milestones
:
[
30
,
60
,
70
,
80
,
90
,
100
,
120
,
140
]
gamma
:
0.5
verbose
:
False
last_epoch
:
-1
regularizer
:
name
:
'
L2'
...
...
ppcls/configs/Vehicle/ResNet50_ReID.yaml
浏览文件 @
18e1cf04
...
...
@@ -2,7 +2,7 @@
Global
:
checkpoints
:
null
pretrained_model
:
null
output_dir
:
"
./output/"
output_dir
:
"
./output
_vehicle_reid
/"
device
:
"
gpu"
save_interval
:
1
eval_during_train
:
True
...
...
ppcls/configs/slim/ResNet50_vehicle_cls_prune.yaml
0 → 100644
浏览文件 @
18e1cf04
# global configs
Global
:
checkpoints
:
null
pretrained_model
:
null
output_dir
:
"
./output_vehicle_cls_prune/"
device
:
"
gpu"
save_interval
:
1
eval_during_train
:
True
eval_interval
:
1
epochs
:
160
print_batch_step
:
10
use_visualdl
:
False
# used for static mode and model export
image_shape
:
[
3
,
224
,
224
]
save_inference_dir
:
"
./inference"
Slim
:
prune
:
name
:
fpgm
pruned_ratio
:
0.3
# model architecture
Arch
:
name
:
"
RecModel"
infer_output_key
:
"
features"
infer_add_softmax
:
False
Backbone
:
name
:
"
ResNet50_last_stage_stride1"
pretrained
:
True
BackboneStopLayer
:
name
:
"
adaptive_avg_pool2d_0"
Neck
:
name
:
"
VehicleNeck"
in_channels
:
2048
out_channels
:
512
Head
:
name
:
"
ArcMargin"
embedding_size
:
512
class_num
:
431
margin
:
0.15
scale
:
32
# loss function config for traing/eval process
Loss
:
Train
:
-
CELoss
:
weight
:
1.0
-
SupConLoss
:
weight
:
1.0
views
:
2
Eval
:
-
CELoss
:
weight
:
1.0
Optimizer
:
name
:
Momentum
momentum
:
0.9
lr
:
name
:
Cosine
learning_rate
:
0.01
last_epoch
:
-1
regularizer
:
name
:
'
L2'
coeff
:
0.0005
# data loader for train and eval
DataLoader
:
Train
:
dataset
:
name
:
"
CompCars"
image_root
:
"
./dataset/CompCars/image/"
label_root
:
"
./dataset/CompCars/label/"
bbox_crop
:
True
cls_label_path
:
"
./dataset/CompCars/train_test_split/classification/train_label.txt"
transform_ops
:
-
ResizeImage
:
size
:
224
-
RandFlipImage
:
flip_code
:
1
-
AugMix
:
prob
:
0.5
-
NormalizeImage
:
scale
:
0.00392157
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
-
RandomErasing
:
EPSILON
:
0.5
sl
:
0.02
sh
:
0.4
r1
:
0.3
mean
:
[
0.
,
0.
,
0.
]
sampler
:
name
:
DistributedRandomIdentitySampler
batch_size
:
128
num_instances
:
2
drop_last
:
False
shuffle
:
True
loader
:
num_workers
:
8
use_shared_memory
:
True
Eval
:
dataset
:
name
:
"
CompCars"
image_root
:
"
./dataset/CompCars/image/"
label_root
:
"
./dataset/CompCars/label/"
cls_label_path
:
"
./dataset/CompCars/train_test_split/classification/test_label.txt"
bbox_crop
:
True
transform_ops
:
-
ResizeImage
:
size
:
224
-
NormalizeImage
:
scale
:
0.00392157
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
sampler
:
name
:
DistributedBatchSampler
batch_size
:
128
drop_last
:
False
shuffle
:
False
loader
:
num_workers
:
8
use_shared_memory
:
True
Metric
:
Train
:
-
TopkAcc
:
topk
:
[
1
,
5
]
Eval
:
-
TopkAcc
:
topk
:
[
1
,
5
]
ppcls/configs/slim/ResNet50_vehicle_cls_quantization.yaml
0 → 100644
浏览文件 @
18e1cf04
# global configs
Global
:
checkpoints
:
null
pretrained_model
:
null
output_dir
:
"
./output_vehicle_cls_pact/"
device
:
"
gpu"
save_interval
:
1
eval_during_train
:
True
eval_interval
:
1
epochs
:
80
print_batch_step
:
10
use_visualdl
:
False
# used for static mode and model export
image_shape
:
[
3
,
224
,
224
]
save_inference_dir
:
"
./inference"
Slim
:
quant
:
name
:
pact
# model architecture
Arch
:
name
:
"
RecModel"
infer_output_key
:
"
features"
infer_add_softmax
:
False
Backbone
:
name
:
"
ResNet50_last_stage_stride1"
pretrained
:
True
BackboneStopLayer
:
name
:
"
adaptive_avg_pool2d_0"
Neck
:
name
:
"
VehicleNeck"
in_channels
:
2048
out_channels
:
512
Head
:
name
:
"
ArcMargin"
embedding_size
:
512
class_num
:
431
margin
:
0.15
scale
:
32
# loss function config for traing/eval process
Loss
:
Train
:
-
CELoss
:
weight
:
1.0
-
SupConLoss
:
weight
:
1.0
views
:
2
Eval
:
-
CELoss
:
weight
:
1.0
Optimizer
:
name
:
Momentum
momentum
:
0.9
lr
:
name
:
Cosine
learning_rate
:
0.001
last_epoch
:
-1
regularizer
:
name
:
'
L2'
coeff
:
0.0005
# data loader for train and eval
DataLoader
:
Train
:
dataset
:
name
:
"
CompCars"
image_root
:
"
./dataset/CompCars/image/"
label_root
:
"
./dataset/CompCars/label/"
bbox_crop
:
True
cls_label_path
:
"
./dataset/CompCars/train_test_split/classification/train_label.txt"
transform_ops
:
-
ResizeImage
:
size
:
224
-
RandFlipImage
:
flip_code
:
1
-
AugMix
:
prob
:
0.5
-
NormalizeImage
:
scale
:
0.00392157
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
-
RandomErasing
:
EPSILON
:
0.5
sl
:
0.02
sh
:
0.4
r1
:
0.3
mean
:
[
0.
,
0.
,
0.
]
sampler
:
name
:
DistributedRandomIdentitySampler
batch_size
:
128
num_instances
:
2
drop_last
:
False
shuffle
:
True
loader
:
num_workers
:
8
use_shared_memory
:
True
Eval
:
dataset
:
name
:
"
CompCars"
image_root
:
"
./dataset/CompCars/image/"
label_root
:
"
./dataset/CompCars/label/"
cls_label_path
:
"
./dataset/CompCars/train_test_split/classification/test_label.txt"
bbox_crop
:
True
transform_ops
:
-
ResizeImage
:
size
:
224
-
NormalizeImage
:
scale
:
0.00392157
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
sampler
:
name
:
DistributedBatchSampler
batch_size
:
128
drop_last
:
False
shuffle
:
False
loader
:
num_workers
:
8
use_shared_memory
:
True
Metric
:
Train
:
-
TopkAcc
:
topk
:
[
1
,
5
]
Eval
:
-
TopkAcc
:
topk
:
[
1
,
5
]
ppcls/configs/slim/ResNet50_vehicle_reid_prune.yaml
浏览文件 @
18e1cf04
...
...
@@ -2,7 +2,7 @@
Global
:
checkpoints
:
null
pretrained_model
:
null
output_dir
:
"
./output/"
output_dir
:
"
./output
_fpgm
/"
device
:
"
gpu"
save_interval
:
1
eval_during_train
:
True
...
...
ppcls/configs/slim/ResNet50_vehicle_reid_quantization.yaml
0 → 100644
浏览文件 @
18e1cf04
# global configs
Global
:
checkpoints
:
null
pretrained_model
:
null
output_dir
:
"
./output_vehicle_reid_pact/"
device
:
"
gpu"
save_interval
:
1
eval_during_train
:
True
eval_interval
:
1
epochs
:
40
print_batch_step
:
10
use_visualdl
:
False
# used for static mode and model export
image_shape
:
[
3
,
224
,
224
]
save_inference_dir
:
"
./inference"
eval_mode
:
"
retrieval"
# for quantizaiton or prune model
Slim
:
## for prune
quant
:
name
:
pact
# model architecture
Arch
:
name
:
"
RecModel"
infer_output_key
:
"
features"
infer_add_softmax
:
False
Backbone
:
name
:
"
ResNet50_last_stage_stride1"
pretrained
:
True
BackboneStopLayer
:
name
:
"
adaptive_avg_pool2d_0"
Neck
:
name
:
"
VehicleNeck"
in_channels
:
2048
out_channels
:
512
Head
:
name
:
"
ArcMargin"
embedding_size
:
512
class_num
:
30671
margin
:
0.15
scale
:
32
# loss function config for traing/eval process
Loss
:
Train
:
-
CELoss
:
weight
:
1.0
-
SupConLoss
:
weight
:
1.0
views
:
2
Eval
:
-
CELoss
:
weight
:
1.0
Optimizer
:
name
:
Momentum
momentum
:
0.9
lr
:
name
:
Cosine
learning_rate
:
0.001
last_epoch
:
-1
regularizer
:
name
:
'
L2'
coeff
:
0.0005
# data loader for train and eval
DataLoader
:
Train
:
dataset
:
name
:
"
VeriWild"
image_root
:
"
./dataset/VeRI-Wild/images/"
cls_label_path
:
"
./dataset/VeRI-Wild/train_test_split/train_list_start0.txt"
transform_ops
:
-
DecodeImage
:
to_rgb
:
True
channel_first
:
False
-
ResizeImage
:
size
:
224
-
RandFlipImage
:
flip_code
:
1
-
AugMix
:
prob
:
0.5
-
NormalizeImage
:
scale
:
0.00392157
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
-
RandomErasing
:
EPSILON
:
0.5
sl
:
0.02
sh
:
0.4
r1
:
0.3
mean
:
[
0.
,
0.
,
0.
]
sampler
:
name
:
DistributedRandomIdentitySampler
batch_size
:
64
num_instances
:
2
drop_last
:
False
shuffle
:
True
loader
:
num_workers
:
6
use_shared_memory
:
True
Eval
:
Query
:
dataset
:
name
:
"
VeriWild"
image_root
:
"
./dataset/VeRI-Wild/images"
cls_label_path
:
"
./dataset/VeRI-Wild/train_test_split/test_3000_id_query.txt"
transform_ops
:
-
DecodeImage
:
to_rgb
:
True
channel_first
:
False
-
ResizeImage
:
size
:
224
-
NormalizeImage
:
scale
:
0.00392157
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
sampler
:
name
:
DistributedBatchSampler
batch_size
:
64
drop_last
:
False
shuffle
:
False
loader
:
num_workers
:
6
use_shared_memory
:
True
Gallery
:
dataset
:
name
:
"
VeriWild"
image_root
:
"
./dataset/VeRI-Wild/images"
cls_label_path
:
"
./dataset/VeRI-Wild/train_test_split/test_3000_id.txt"
transform_ops
:
-
DecodeImage
:
to_rgb
:
True
channel_first
:
False
-
ResizeImage
:
size
:
224
-
NormalizeImage
:
scale
:
0.00392157
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
sampler
:
name
:
DistributedBatchSampler
batch_size
:
64
drop_last
:
False
shuffle
:
False
loader
:
num_workers
:
6
use_shared_memory
:
True
Metric
:
Eval
:
-
Recallk
:
topk
:
[
1
,
5
]
-
mAP
:
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录