Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
PET_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김성주
2020-05-24 23:43:18 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c3bb68094db34b026b43f0ca59b32553d7bea24f
c3bb6809
1 parent
729b5d8b
fixed indent and import issue
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
46 deletions
code/yolov3/eval.py
code/yolov3/train.py
code/yolov3/eval.py
View file @
c3bb680
...
...
@@ -10,6 +10,7 @@ from data_utils import get_batch_data
from
misc_utils
import
parse_anchors
,
read_class_names
,
AverageMeter
from
eval_utils
import
evaluate_on_cpu
,
evaluate_on_gpu
,
get_preds_gpu
,
voc_eval
,
parse_gt_rec
from
nms_utils
import
gpu_nms
from
tfrecord_utils
import
TFRecordIterator
from
model
import
yolov3
...
...
code/yolov3/train.py
View file @
c3bb680
...
...
@@ -57,7 +57,7 @@ for y in y_true:
### Model definition
yolo_model
=
yolov3
(
class_num
,
anchors
,
use_label_smooth
,
use_focal_loss
,
batch_norm_decay
,
weight_decay
,
use_static_shape
=
False
)
yolo_model
=
yolov3
(
args
.
class_num
,
args
.
anchors
,
args
.
use_label_smooth
,
args
.
use_focal_loss
,
args
.
batch_norm_decay
,
args
.
weight_decay
,
use_static_shape
=
False
)
with
tf
.
variable_scope
(
'yolov3'
):
pred_feature_maps
=
yolo_model
.
forward
(
image
,
is_training
=
is_training
)
...
...
@@ -67,14 +67,14 @@ y_pred = yolo_model.predict(pred_feature_maps)
l2_loss
=
tf
.
losses
.
get_regularization_loss
()
saver_to_restore
=
tf
.
train
.
Saver
(
var_list
=
tf
.
contrib
.
framework
.
get_variables_to_restore
(
include
=
restore_include
,
exclude
=
restore_exclude
))
update_vars
=
tf
.
contrib
.
framework
.
get_variables_to_restore
(
include
=
update_part
)
saver_to_restore
=
tf
.
train
.
Saver
(
var_list
=
tf
.
contrib
.
framework
.
get_variables_to_restore
(
include
=
args
.
restore_include
,
exclude
=
args
.
restore_exclude
))
update_vars
=
tf
.
contrib
.
framework
.
get_variables_to_restore
(
include
=
args
.
update_part
)
global_step
=
tf
.
Variable
(
float
(
args
.
global_step
),
trainable
=
False
,
collections
=
[
tf
.
GraphKeys
.
LOCAL_VARIABLES
])
if
use_warm_up
:
learning_rate
=
tf
.
cond
(
tf
.
less
(
global_step
,
train_batch_num
*
warm_up_epoch
),
lambda
:
learning_rate_init
*
global_step
/
(
train_batch_num
*
warm_up_epoch
),
if
args
.
use_warm_up
:
learning_rate
=
tf
.
cond
(
tf
.
less
(
global_step
,
args
.
train_batch_num
*
args
.
warm_up_epoch
),
lambda
:
args
.
learning_rate_init
*
args
.
global_step
/
(
args
.
train_batch_num
*
args
.
warm_up_epoch
),
lambda
:
config_learning_rate
(
args
,
global_step
-
args
.
train_batch_num
*
args
.
warm_up_epoch
))
else
:
learning_rate
=
config_learning_rate
(
args
,
global_step
)
...
...
@@ -190,43 +190,43 @@ with tf.Session() as sess:
epoch
,
int
(
__global_step
),
best_mAP
,
val_loss_total
.
average
,
__lr
))
## all epoches end
sess
.
run
(
val_init_op
)
val_loss_total
,
val_loss_xy
,
val_loss_wh
,
val_loss_conf
,
val_loss_class
=
AverageMeter
(),
AverageMeter
(),
AverageMeter
(),
AverageMeter
(),
AverageMeter
()
val_preds
=
[]
for
j
in
trange
(
val_img_cnt
):
__image_ids
,
__y_pred
,
__loss
=
sess
.
run
([
image_ids
,
y_pred
,
loss
],
feed_dict
=
{
is_training
:
False
})
pred_content
=
get_preds_gpu
(
sess
,
gpu_nms_op
,
pred_boxes_flag
,
pred_scores_flag
,
__image_ids
,
__y_pred
)
val_preds
.
extend
(
pred_content
)
val_loss_total
.
update
(
__loss
[
0
])
val_loss_xy
.
update
(
__loss
[
1
])
val_loss_wh
.
update
(
__loss
[
2
])
val_loss_conf
.
update
(
__loss
[
3
])
val_loss_class
.
update
(
__loss
[
4
])
# calc mAP
rec_total
,
prec_total
,
ap_total
=
AverageMeter
(),
AverageMeter
(),
AverageMeter
()
gt_dict
=
parse_gt_rec
(
val_file
,
'GZIP'
,
img_size
,
letterbox_resize
)
info
=
'======> Epoch: {}, global_step: {}, lr: {:.6g} <======
\n
'
.
format
(
epoch
,
__global_step
,
__lr
)
for
ii
in
range
(
class_num
):
npos
,
nd
,
rec
,
prec
,
ap
=
voc_eval
(
gt_dict
,
val_preds
,
ii
,
iou_thres
=
eval_threshold
,
use_07_metric
=
use_voc_07_metric
)
info
+=
'EVAL: Class {}: Recall: {:.4f}, Precision: {:.4f}, AP: {:.4f}
\n
'
.
format
(
ii
,
rec
,
prec
,
ap
)
rec_total
.
update
(
rec
,
npos
)
prec_total
.
update
(
prec
,
nd
)
ap_total
.
update
(
ap
,
1
)
mAP
=
ap_total
.
average
info
+=
'EVAL: Recall: {:.4f}, Precison: {:.4f}, mAP: {:.4f}
\n
'
.
format
(
rec_total
.
average
,
prec_total
.
average
,
mAP
)
info
+=
'EVAL: loss: total: {:.2f}, xy: {:.2f}, wh: {:.2f}, conf: {:.2f}, class: {:.2f}
\n
'
.
format
(
val_loss_total
.
average
,
val_loss_xy
.
average
,
val_loss_wh
.
average
,
val_loss_conf
.
average
,
val_loss_class
.
average
)
print
(
info
)
if
save_optimizer
and
mAP
>
best_mAP
:
best_mAP
=
mAP
saver_best
.
save
(
sess
,
save_dir
+
'best_model_Epoch_{}_step_{}_mAP_{:.4f}_loss_{:.4f}_lr_{:.7g}'
.
format
(
epoch
,
int
(
__global_step
),
best_mAP
,
val_loss_total
.
average
,
__lr
))
\ No newline at end of file
sess
.
run
(
val_init_op
)
val_loss_total
,
val_loss_xy
,
val_loss_wh
,
val_loss_conf
,
val_loss_class
=
AverageMeter
(),
AverageMeter
(),
AverageMeter
(),
AverageMeter
(),
AverageMeter
()
val_preds
=
[]
for
j
in
trange
(
args
.
val_img_cnt
):
__image_ids
,
__y_pred
,
__loss
=
sess
.
run
([
image_ids
,
y_pred
,
loss
],
feed_dict
=
{
is_training
:
False
})
pred_content
=
get_preds_gpu
(
sess
,
gpu_nms_op
,
pred_boxes_flag
,
pred_scores_flag
,
__image_ids
,
__y_pred
)
val_preds
.
extend
(
pred_content
)
val_loss_total
.
update
(
__loss
[
0
])
val_loss_xy
.
update
(
__loss
[
1
])
val_loss_wh
.
update
(
__loss
[
2
])
val_loss_conf
.
update
(
__loss
[
3
])
val_loss_class
.
update
(
__loss
[
4
])
# calc mAP
rec_total
,
prec_total
,
ap_total
=
AverageMeter
(),
AverageMeter
(),
AverageMeter
()
gt_dict
=
parse_gt_rec
(
args
.
val_file
,
'GZIP'
,
args
.
img_size
,
args
.
letterbox_resize
)
info
=
'======> Epoch: {}, global_step: {}, lr: {:.6g} <======
\n
'
.
format
(
epoch
,
__global_step
,
__lr
)
for
ii
in
range
(
args
.
class_num
):
npos
,
nd
,
rec
,
prec
,
ap
=
voc_eval
(
gt_dict
,
val_preds
,
ii
,
iou_thres
=
args
.
eval_threshold
,
use_07_metric
=
args
.
use_voc_07_metric
)
info
+=
'EVAL: Class {}: Recall: {:.4f}, Precision: {:.4f}, AP: {:.4f}
\n
'
.
format
(
ii
,
rec
,
prec
,
ap
)
rec_total
.
update
(
rec
,
npos
)
prec_total
.
update
(
prec
,
nd
)
ap_total
.
update
(
ap
,
1
)
mAP
=
ap_total
.
average
info
+=
'EVAL: Recall: {:.4f}, Precison: {:.4f}, mAP: {:.4f}
\n
'
.
format
(
rec_total
.
average
,
prec_total
.
average
,
mAP
)
info
+=
'EVAL: loss: total: {:.2f}, xy: {:.2f}, wh: {:.2f}, conf: {:.2f}, class: {:.2f}
\n
'
.
format
(
val_loss_total
.
average
,
val_loss_xy
.
average
,
val_loss_wh
.
average
,
val_loss_conf
.
average
,
val_loss_class
.
average
)
print
(
info
)
if
args
.
save_optimizer
and
mAP
>
best_mAP
:
best_mAP
=
mAP
saver_best
.
save
(
sess
,
args
.
save_dir
+
'best_model_Epoch_{}_step_{}_mAP_{:.4f}_loss_{:.4f}_lr_{:.7g}'
.
format
(
epoch
,
int
(
__global_step
),
best_mAP
,
val_loss_total
.
average
,
__lr
))
\ No newline at end of file
...
...
Please
register
or
login
to post a comment