Recently, I am trying to fine-tune the EfficientDet-D4 model available in TensorFlow model Zoo repository
(http://download.tensorflow.org/models/object_detection/tf2/20200711/efficientdet_d4_coco17_tpu-32.tar.gz)
To Fine-Tuning this model, I have followed the steps established in the following guide (https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html). The dataset I want to use is the Visdrone dataset (http://aiskyeye.com/). When the model goes through the 2000 step, the accuracy decays to 0 and does not detect anything.
Below, I attach the configuration file used for fine-tuning:
# SSD with EfficientNet-b4 + BiFPN feature extractor,
# shared box predictor and focal loss (a.k.a EfficientDet-d4).
# See EfficientDet, Tan et al, https://arxiv.org/abs/1911.09070
# See Lin et al, https://arxiv.org/abs/1708.02002
# Trained on COCO, initialized from an EfficientNet-b4 checkpoint.
#
# Train on TPU-32
model {
ssd {
inplace_batchnorm_update: true
freeze_batchnorm: false
num_classes: 90
add_background_class: false
box_coder {
faster_rcnn_box_coder {
y_scale: 10.0
x_scale: 10.0
height_scale: 5.0
width_scale: 5.0
}
}
matcher {
argmax_matcher {
matched_threshold: 0.5
unmatched_threshold: 0.5
ignore_thresholds: false
negatives_lower_than_unmatched: true
force_match_for_each_row: true
use_matmul_gather: true
}
}
similarity_calculator {
iou_similarity {
}
}
encode_background_as_zeros: true
anchor_generator {
multiscale_anchor_generator {
min_level: 3
max_level: 7
anchor_scale: 4.0
aspect_ratios: [1.0, 2.0, 0.5]
scales_per_octave: 3
}
}
image_resizer {
keep_aspect_ratio_resizer {
min_dimension: 1024
max_dimension: 1024
pad_to_max_dimension: true
}
}
box_predictor {
weight_shared_convolutional_box_predictor {
depth: 224
class_prediction_bias_init: -4.6
conv_hyperparams {
force_use_bias: true
activation: SWISH
regularizer {
l2_regularizer {
weight: 0.00004
}
}
initializer {
random_normal_initializer {
stddev: 0.01
mean: 0.0
}
}
batch_norm {
scale: true
decay: 0.99
epsilon: 0.001
}
}
num_layers_before_predictor: 4
kernel_size: 3
use_depthwise: true
}
}
feature_extractor {
type: 'ssd_efficientnet-b4_bifpn_keras'
bifpn {
min_level: 3
max_level: 7
num_iterations: 7
num_filters: 224
}
conv_hyperparams {
force_use_bias: true
activation: SWISH
regularizer {
l2_regularizer {
weight: 0.00004
}
}
initializer {
truncated_normal_initializer {
stddev: 0.03
mean: 0.0
}
}
batch_norm {
scale: true,
decay: 0.99,
epsilon: 0.001,
}
}
}
loss {
classification_loss {
weighted_sigmoid_focal {
alpha: 0.25
gamma: 1.5
}
}
localization_loss {
weighted_smooth_l1 {
}
}
classification_weight: 1.0
localization_weight: 1.0
}
normalize_loss_by_num_matches: true
normalize_loc_loss_by_codesize: true
post_processing {
batch_non_max_suppression {
score_threshold: 1e-8
iou_threshold: 0.5
max_detections_per_class: 100
max_total_detections: 100
}
score_converter: SIGMOID
}
}
}
train_config: {
fine_tune_checkpoint: "/home/models/efd4/checkpoint/ckpt-0"
fine_tune_checkpoint_version: V2
fine_tune_checkpoint_type: "detection"
batch_size: 1
sync_replicas: true
startup_delay_steps: 0
replicas_to_aggregate: 8
use_bfloat16: true
num_steps: 150000
data_augmentation_options {
random_horizontal_flip {
}
}
data_augmentation_options {
random_scale_crop_and_pad_to_square {
output_size: 1024
scale_min: 0.1
scale_max: 2.0
}
}
optimizer {
momentum_optimizer: {
learning_rate: {
cosine_decay_learning_rate {
learning_rate_base: 0.001
total_steps: 150000
warmup_learning_rate: .0001
warmup_steps: 500
}
}
momentum_optimizer_value: 0.9
}
use_moving_average: false
}
max_number_of_boxes: 100
unpad_groundtruth_tensors: false
}
train_input_reader: {
label_map_path: "/home/labels/label_map.txt"
tf_record_input_reader {
input_path: "/home/records/train.tfrecord"
}
}
eval_config: {
metrics_set: "coco_detection_metrics"
use_moving_averages: false
batch_size: 1;
}
eval_input_reader: {
label_map_path: "/home/labels/label_map.txt"
shuffle: false
num_epochs: 1
tf_record_input_reader {
input_path: "/home/records/validation.tfrecord"
}
}
I try modify parameters like learning-rate, etc but doesnt work
Related
I want to add two numbers in vue
data() {
return {
details: {
num1: 100,
num2: 500,
total: num1 + num2
}
}
}
Is this not possible and bad practice? I can create a computed but this as a temp shortcut would be useful. Is it just the scope I have wrong?
It's a very bad practice!
In Vue.js you should always use computed properties for any calculation.
But in your case you should do something like this:
<template>
<div>{{details.total()}}</div>
</template>
<script>
export default {
data() {
return {
details: {
num1: 100,
num2: 500,
total: () => this.details.num1 + this.details.num2
}
}
}
}
}
</script>
I have a document list that consists of:
time
sessionId
appv
museum
I would like to use the couchDB map/reduce function to get the result:
key : sessionId, value : {begin : time, end: time, appv : appv, museum : museum}
for the begin value: the minimum time value.
for the end value: the maximum time value
Currently I can have the minimum and maximum value with this code:
MAP :
function(doc) {
if(doc.sessionId) {
emit(doc.sessionId, [doc.time])
}
}
REDUCE :
function(keys, values, rereduce) {
if (rereduce) {
return {
'min': values.reduce(function(a, b) { return Math.min(a, b.min) }, Infinity),
'max': values.reduce(function(a, b) { return Math.max(a, b.max) }, -Infinity),
}
} else {
return {
'min': Math.min.apply(null, values),
'max': Math.max.apply(null, values),
}
}
}
RESULT :
{"rows":[
{"key":"fromDev1548326238156","value":{"min":2,"max":999}}
]}
And when I use this map function:
function(doc) {
if(doc.sessionId) {
emit(doc.sessionId, [doc.time, doc.museum, doc.appv])
}
}
I can't find the reduce function that allows me to get the result I want
Can you help me?
I currently retrained an ssd mobile net v2 model using the tutorial. I ran the following in command line to execute the retraining. It retrained the entire model.
(tensorflow) c:\models-master\research>python object_detection/legacy/train.py --logtostderr --train_dir=training/model2/ --pipeline_config_path=training/ssd_mobilenet_v2_2.config
I set the config file as such:
# SSD with Mobilenet v2 configuration for MSCOCO Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
# should be configured.
model {
ssd {
num_classes: 1
box_coder {
faster_rcnn_box_coder {
y_scale: 10.0
x_scale: 10.0
height_scale: 5.0
width_scale: 5.0
}
}
matcher {
argmax_matcher {
matched_threshold: 0.5
unmatched_threshold: 0.5
ignore_thresholds: false
negatives_lower_than_unmatched: true
force_match_for_each_row: true
}
}
similarity_calculator {
iou_similarity {
}
}
anchor_generator {
ssd_anchor_generator {
num_layers: 6
min_scale: 0.2
max_scale: 0.95
aspect_ratios: 1.0
aspect_ratios: 2.0
aspect_ratios: 0.5
aspect_ratios: 3.0
aspect_ratios: 0.3333
}
}
image_resizer {
fixed_shape_resizer {
height: 300
width: 300
}
}
box_predictor {
convolutional_box_predictor {
min_depth: 0
max_depth: 0
num_layers_before_predictor: 0
use_dropout: false
dropout_keep_probability: 0.8
kernel_size: 3
box_code_size: 4
apply_sigmoid_to_scores: false
conv_hyperparams {
activation: RELU_6,
regularizer {
l2_regularizer {
weight: 0.00004
}
}
initializer {
truncated_normal_initializer {
stddev: 0.03
mean: 0.0
}
}
batch_norm {
train: true,
scale: true,
center: true,
decay: 0.9997,
epsilon: 0.001,
}
}
}
}
feature_extractor {
type: 'ssd_mobilenet_v2'
min_depth: 16
depth_multiplier: 1.0
use_depthwise: true
conv_hyperparams {
activation: RELU_6,
regularizer {
l2_regularizer {
weight: 0.00004
}
}
initializer {
truncated_normal_initializer {
stddev: 0.03
mean: 0.0
}
}
batch_norm {
train: true,
scale: true,
center: true,
decay: 0.9997,
epsilon: 0.001,
}
}
}
loss {
classification_loss {
weighted_sigmoid {
}
}
localization_loss {
weighted_smooth_l1 {
}
}
hard_example_miner {
num_hard_examples: 3000
iou_threshold: 0.99
loss_type: CLASSIFICATION
max_negatives_per_positive: 3
min_negatives_per_image: 3
}
classification_weight: 1.0
localization_weight: 1.0
}
normalize_loss_by_num_matches: true
post_processing {
batch_non_max_suppression {
score_threshold: 1e-8
iou_threshold: 0.6
max_detections_per_class: 100
max_total_detections: 100
}
score_converter: SIGMOID
}
}
}
train_config: {
batch_size: 24
optimizer {
rms_prop_optimizer: {
learning_rate: {
exponential_decay_learning_rate {
initial_learning_rate: 0.004
decay_steps: 800720
decay_factor: 0.95
}
}
momentum_optimizer_value: 0.9
decay: 0.9
epsilon: 1.0
}
}
fine_tune_checkpoint: "D:/Databases/Coco/cctv/tf/ssd_mobilenet_v2_coco_2018_03_29/model.ckpt"
fine_tune_checkpoint_type: "detection"
# Note: The below line limits the training process to 200K steps, which we
# empirically found to be sufficient enough to train the pets dataset. This
# effectively bypasses the learning rate schedule (the learning rate will
# never decay). Remove the below line to train indefinitely.
num_steps: 200000
data_augmentation_options {
random_horizontal_flip {
}
}
data_augmentation_options {
ssd_random_crop {
}
}
}
train_input_reader: {
tf_record_input_reader {
input_path: "D:/Code/Image/cctvmodel/tfrecordfinalALL/train2.record"
}
label_map_path: "D:/Code/Image/cctvmodel/label_map.pbtxt"
}
eval_config: {
num_examples: 8000
# Note: The below line limits the evaluation process to 10 evaluations.
# Remove the below line to evaluate indefinitely.
max_evals: 10
}
eval_input_reader: {
tf_record_input_reader {
input_path: "D:/Code/Image/cctvmodel/tfrecordfinalALL/test2.record"
}
label_map_path: "D:/Code/Image/cctvmodel/label_map.pbtxt"
shuffle: false
num_readers: 1
How can one retrain only the last fully connected layer? Or does one freeze the upper layers/weight and retrain?
Note that in the pretrained model folder there is .pb file and a single checkpoint file as shown below:
I have found a link for fine tuning at existing checkpoint. More details can be found herelink. The example code is :
$ DATASET_DIR=/tmp/flowers
$ TRAIN_DIR=/tmp/flowers-models/inception_v3
$ CHECKPOINT_PATH=/tmp/my_checkpoints/inception_v3.ckpt
$ python train_image_classifier.py \
--train_dir=${TRAIN_DIR} \
--dataset_dir=${DATASET_DIR} \
--dataset_name=flowers \
--dataset_split_name=train \
--model_name=inception_v3 \
--checkpoint_path=${CHECKPOINT_PATH} \
--checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
--trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits
How should I set the checkpoints to ensure it trains the last fully connected layer?
I am encountering this error on AWS c5.4xlarge instance. Note my batch size is 1 error is
W tensorflow/core/framework/op_kernel.cc:1192] Resource exhausted: OOM when allocating tensor with shape[2976,4464,3]
2018-01-26 02:18:05.895855: W tensorflow/core/framework/op_kernel.cc:1192] Resource exhausted: OOM when allocating tensor with shape[1,2976,4464,3]
Killed
I was able to resolve this by stepping up the RAM, but it takes ridiculous 72gb of ram on aws (c5 9xlarge instance) to get it running How do I optimize this by using less RAM note (batch size:1)
`
I am using the highlighted instance in the above figure which ran out of RAM
I am referring to: https://github.com/tensorflow/models/tree/master/research/object_detection
the config file I am using is:
# Faster R-CNN with Inception Resnet v2, Atrous version;
# Configured for MSCOCO Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
# should be configured.
model {
faster_rcnn {
num_classes: 1
image_resizer {
keep_aspect_ratio_resizer {
min_dimension: 600
max_dimension: 1024
}
}
feature_extractor {
type: 'faster_rcnn_inception_resnet_v2'
first_stage_features_stride: 8
}
first_stage_anchor_generator {
grid_anchor_generator {
scales: [0.25, 0.5, 1.0, 2.0]
aspect_ratios: [0.5, 1.0, 2.0]
height_stride: 8
width_stride: 8
}
}
first_stage_atrous_rate: 2
first_stage_box_predictor_conv_hyperparams {
op: CONV
regularizer {
l2_regularizer {
weight: 0.0
}
}
initializer {
truncated_normal_initializer {
stddev: 0.01
}
}
}
first_stage_nms_score_threshold: 0.0
first_stage_nms_iou_threshold: 0.7
first_stage_max_proposals: 300
first_stage_localization_loss_weight: 2.0
first_stage_objectness_loss_weight: 1.0
initial_crop_size: 17
maxpool_kernel_size: 1
maxpool_stride: 1
second_stage_box_predictor {
mask_rcnn_box_predictor {
use_dropout: false
dropout_keep_probability: 1.0
fc_hyperparams {
op: FC
regularizer {
l2_regularizer {
weight: 0.0
}
}
initializer {
variance_scaling_initializer {
factor: 1.0
uniform: true
mode: FAN_AVG
}
}
}
}
}
second_stage_post_processing {
batch_non_max_suppression {
score_threshold: 0.0
iou_threshold: 0.6
max_detections_per_class: 100
max_total_detections: 100
}
score_converter: SOFTMAX
}
second_stage_localization_loss_weight: 2.0
second_stage_classification_loss_weight: 1.0
}
}
train_config: {
batch_size: 1
optimizer {
momentum_optimizer: {
learning_rate: {
manual_step_learning_rate {
initial_learning_rate: 0.0003
schedule {
step: 0
learning_rate: .0003
}
schedule {
step: 900000
learning_rate: .00003
}
schedule {
step: 1200000
learning_rate: .000003
}
}
}
momentum_optimizer_value: 0.9
}
use_moving_average: false
}
gradient_clipping_by_norm: 10.0
fine_tune_checkpoint: "faster_rcnn_resnet101_coco_2017_11_08/model.ckpt"
from_detection_checkpoint: true
# Note: The below line limits the training process to 200K steps, which we
# empirically found to be sufficient enough to train the pets dataset. This
# effectively bypasses the learning rate schedule (the learning rate will
# never decay). Remove the below line to train indefinitely.
num_steps: 200000
data_augmentation_options {
random_horizontal_flip {
}
}
}
train_input_reader: {
tf_record_input_reader {
input_path: "data/train.record"
}
label_map_path: "data/object-detection.pbtxt"
}
eval_config: {
num_examples: 8000
# Note: The below line limits the evaluation process to 10 evaluations.
# Remove the below line to evaluate indefinitely.
max_evals: 10
}
eval_input_reader: {
tf_record_input_reader {
input_path: "data/test.record"
}
label_map_path: "data/object-detection.pbtxt"
shuffle: false
num_readers: 1
num_epochs: 1
}
my pbtxt file is:
item {
id: 1
name: 'name_of_object'
}
I was trying to create a difference if y == 0, however when I put the last 'cube' in it fills in other parts of the shape that should not be filled in & it doesn't even cut out what it should've. However, when I comment out the final cube it works fine (except it doesn't have the last difference obviously). I have tried using openscad.net & the software. Both of them have the same effect. What am I doing wrong?
With cube uncommented
With cube commented
s = 20+8; //Block size in mm
l = 2; //In "blocks"
w = 2; //In "blocks"
h = 40; //In mm
t = 1;
for (x = [0:l-1]) {
for (y = [0:w-1]) {
translate([s*x-s*l/2, s*y-s*w/2, -h/2]) {
if (x==0) {
translate([-s*(2/28)-t, s*(16/28)+t/2, 0]) {
cube([s*(2/28)+t, s*(8/28)-t, h]);
}
translate([-s*(4/28), s*(14/28)+t/2, 0]) {
cube([s*(2/28)-t, s*(12/28)-t, h]);
}
}
if (x==l-1) {
translate([s, s*(4/28)+t/2, 0]) {
cube([s*(2/28)+t, s*(8/28)-t, h]);
}
translate([s+s*(2/28)+t, s*(2/28)+t/2, 0]) {
cube([s*(2/28)-t, s*(12/28)-t, h]);
}
}
if (y==0) {
translate([s*(4/28)+t/2, -s*(2/28)-t, 0]) {
cube([s*(8/28)-t, s*(2/28)+t, h]);
}
translate([s*(2/28)+t/2, -s*(4/28), 0]) {
cube([s*(12/28)-t, s*(2/28)-t, h]);
}
}
difference() {
cube([s, s, h]);
intersection() {
if (x == 0) {
translate([0, s*(4/28), 0]) {
cube([s*(2/28), s*(8/28), h]);
}
translate([s*(2/28), s*(2/28), 0]) {
cube([s*(2/28), s*(12/28), h]);
}
}
if (x==l-1) {
translate([s-s*(4/28), s*(14/28), 0]) {
cube([s*(2/28), s*(12/28), h]);
}
translate([s-s*(2/28), s*(16/28), 0]) {
cube([s*(2/28), s*(8/28), h]);
}
}
if (y==0) {
translate([s*(14/28), -s*(4/28), 0]) {
cube([s*(12/28), s*(2/28), h]);
}
}
}
}
}
}
}
The reason for your results seems to be that when y==0, your intersection results in an empty object, hence nothing is subtracted.
If you slim down your design to a smaller example exhibiting this behavior, it would be a lot easier to debug.
Hint: You can use the # and % operators to highlight objects for debugging (# includes it in the CSG tree, % removes it from the CSG tree).
To add to kintel's answer, I think you intended to do a union() there at line 38, also putting things into module helps a lot when reusing or updating things in the future.