Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
9169f7d
Start of parsing of xml files for transfer learning
SamBlakeman Aug 1, 2019
7ea9cfa
More parsing
SamBlakeman Aug 2, 2019
cb8ed6d
Deletion of xml file
SamBlakeman Aug 5, 2019
8b34af2
updated checking of checkpoint fn
jackattack1415 Aug 6, 2019
6ec44bd
Dealing with empty xml files
SamBlakeman Aug 6, 2019
688e3b0
More parsing of both the input and output data for transfer learning
SamBlakeman Aug 7, 2019
9e1c1c4
benchmarking for performing object detection
jackattack1415 Aug 7, 2019
5456c9b
edited params and run_pipeline so they can run and be tested
jackattack1415 Aug 7, 2019
acb2bc3
Fixing issues with loading videos for the cvat dataset
SamBlakeman Aug 7, 2019
c0601a3
Working parsing of input and output data for transfer
SamBlakeman Aug 8, 2019
1e45009
pulled dev
jackattack1415 Aug 9, 2019
fd32950
merged in sam's xml parsing branch
jackattack1415 Aug 9, 2019
6c0e245
refactoring
jackattack1415 Aug 9, 2019
d2d86ae
Merge branch 'object_detect_in_pipeline' of https://github.com/dssg/a…
jackattack1415 Aug 11, 2019
fbbe066
moved functions and other files from other github repo over
jackattack1415 Aug 11, 2019
cc2fa82
converted args.py to a .yml file
jackattack1415 Aug 11, 2019
e30fd46
refactoring changes
jackattack1415 Aug 11, 2019
fbff360
movement of files over from other github repo
jackattack1415 Aug 11, 2019
87c664c
madea few changes to sam's script
jackattack1415 Aug 11, 2019
dab9652
added function to load training params
jackattack1415 Aug 11, 2019
483f86c
converted everything away from args instead to the training_parameter…
jackattack1415 Aug 11, 2019
d0cb8c2
added lines to save a text file to be referenced
jackattack1415 Aug 11, 2019
6df30f2
fixed typo in epochs
jackattack1415 Aug 11, 2019
d247bc3
added missing package
jackattack1415 Aug 11, 2019
23028ee
formatted txt truth file so it fits requisite format for trainng
jackattack1415 Aug 11, 2019
e1b71a0
made changes to account for bug fixes
jackattack1415 Aug 11, 2019
b52a90a
legacy scripts kept in for the time being
jackattack1415 Aug 11, 2019
07a5bfa
changed to yolo_tf
jackattack1415 Aug 12, 2019
89461ea
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
260deb0
added paths so that sys is updated
jackattack1415 Aug 12, 2019
fc49252
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
9dae620
changed dir
jackattack1415 Aug 12, 2019
8c7ca7a
new transfer_learning pipeline script
jackattack1415 Aug 12, 2019
97aba35
fixed a quick bug with the configuration of the learning rate
jackattack1415 Aug 12, 2019
82d87f0
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
aecd924
fixed functions so they work with the transfer learning pipeline code
jackattack1415 Aug 12, 2019
5f29c33
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
ed8a895
fixed a bug with save_epoch
jackattack1415 Aug 12, 2019
9d14379
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
2866aed
batch size --> num batches
jackattack1415 Aug 12, 2019
78c0508
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
45b7da8
added evaluation on gpu instead of wrong fn
jackattack1415 Aug 12, 2019
58f364b
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
b53827b
reverted changes from last commit
jackattack1415 Aug 12, 2019
6aec004
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
0f7a52f
speed up map calculation
jackattack1415 Aug 12, 2019
4321336
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
3f54aab
fixed transfer_learning unifying code
jackattack1415 Aug 12, 2019
3840c20
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
615b0a0
changed selected labels idx selection because dict
jackattack1415 Aug 12, 2019
914c874
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
53bddb2
removed print statements
jackattack1415 Aug 12, 2019
e06f246
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
692d3fb
checking the map with print statements
jackattack1415 Aug 12, 2019
31203d8
hopefully remove nans
jackattack1415 Aug 12, 2019
81ae864
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
f5de8da
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
9213449
print statements added to debug
jackattack1415 Aug 12, 2019
8ffeaaa
fixed error with selected_labels_idx
jackattack1415 Aug 12, 2019
6cc8bc9
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 12, 2019
7c4b583
seeing if label idxs are actually strings
jackattack1415 Aug 12, 2019
8b50384
try to run with just 50 epochs
jackattack1415 Aug 13, 2019
d6fdd4e
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 13, 2019
0fc49ca
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 13, 2019
f4f3286
puts trained model in correct directory
jackattack1415 Aug 13, 2019
b3c3070
moved so i can run the code
jackattack1415 Aug 13, 2019
62ffdf5
changed so can try trained model
jackattack1415 Aug 13, 2019
77af1cf
changed path to labels
jackattack1415 Aug 13, 2019
97af1ee
break after 10 xmls
jackattack1415 Aug 13, 2019
2dccde7
trying out
jackattack1415 Aug 13, 2019
66464c0
print statement added to track downloading prog
jackattack1415 Aug 13, 2019
b40843f
changes committed
jackattack1415 Aug 13, 2019
0fa1dac
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 13, 2019
47cc6fb
correct break message now after 10 counts
jackattack1415 Aug 13, 2019
d0975d7
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 13, 2019
d4109b9
ok now break should actually work
jackattack1415 Aug 13, 2019
255efe8
added cvat annotations to the mix
jackattack1415 Aug 13, 2019
c03f217
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 13, 2019
f9ba589
got rid of print statements
jackattack1415 Aug 13, 2019
fb335c8
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 13, 2019
2d89d5b
see how transfer learning performed
jackattack1415 Aug 14, 2019
49284fd
merged from dev
jackattack1415 Aug 14, 2019
f53498c
delete example.py (not used)
jackattack1415 Aug 14, 2019
04016be
delete args.py (not used)
jackattack1415 Aug 14, 2019
7076e92
delete test.py (not used)
jackattack1415 Aug 14, 2019
ba4a9d8
added version to requirements
jackattack1415 Aug 19, 2019
8b6409d
merged dev
jackattack1415 Aug 19, 2019
d663fc3
deleted unused files
jackattack1415 Aug 19, 2019
3740c10
patching to address comments from recent pr
jackattack1415 Aug 20, 2019
61f855d
broke down tensorflow_training_utils into specific scripts
jackattack1415 Aug 21, 2019
0e56977
patching
jackattack1415 Aug 21, 2019
b64d5bb
Merge branch 'transfer_learning' of https://github.com/dssg/air_pollu…
jackattack1415 Aug 23, 2019
cc25d3a
merged from dev
jackattack1415 Aug 23, 2019
3ef194b
added blank lines to make pep8 compliant
jackattack1415 Aug 23, 2019
2d90db2
removed hard coding
jackattack1415 Aug 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions conf/base/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ data_renaming: # TODO: remove later when renaming finished

modelling:
# obj detection
detection_model: "yolov3-tiny"
detection_model: "yolov3_tf"
detection_implementation: "cvlib"
detection_iou_threshold: 0.05
detection_confidence_threshold: 0.2
# TODO: change nms threshold to iou threshold
# TODO: change nms threshold to iou threshold
detection_nms_threshold: 0.2

# tracking
selected_labels: ["car", "truck", "bus", "motorbike"]
opencv_tracker_type: "csrt"
Expand Down
8 changes: 7 additions & 1 deletion conf/base/paths.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ s3_paths:
s3_camera_details: "ref/camera_details/camera_details.json"

s3_frame_level: "frame_level/" # TODO DELETE THIS
s3_profile: "dssg" # TODO: change this for user?
s3_profile: "dssg" # TODO: change this for user?
s3_creds: "dev_s3" # TODO: CHANGE TO JUST S3
s3_detection_model: "ref/model_conf/"
s3_cvat_annotations: "ref/annotations/cvat/"
s3_detrac_annotations: "ref/annotations/detrac/"
s3_detrac_images: "raw/images/detrac/"
s3_cvat_training_annotations: "ref/annotations/cvat_train/"

local_paths:
temp_video: "data/temp/videos/"
temp_raw_images: "data/temp/raw_images/"
temp_raw_video: "data/temp/raw_videos/"
temp_frame_level: "data/temp/frame_level/"
temp_video_level: "data/temp/video_level/"
temp_annotation: "data/temp/annotation/"
temp_setup: "data/temp/setup/"

video_names: "data/ref/video_names/"
Expand Down
34 changes: 34 additions & 0 deletions conf/base/training_parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
training:
num_batches : 10
letterbox_resize : True # Whether to use letterbox resize, i.e., keep the original aspect ratio in the resized img.
total_epochs : 1000
train_evaluation_step : 100 # Evaluate on the training batch after some steps.
val_evaluation_epoch : 2 # Evaluate on the validation dataset after some epochs. Set to None to evaluate all epoch.
save_epoch : 10 # Save the model after some epochs.
batch_norm_decay : 0.99 # decay in bn ops
weight_decay : 0.0005 # l2 weight decay
global_step : 0 # used when resuming training
warm_up_epoch : 3 # set to larger value if gradient explodes
num_threads : 10 # Number of threads for image processing used in tf.data pipeline.
prefetech_buffer : 5 # Prefetech_buffer used in tf.data pipeline.
trained_model_name : 'yolov3_traffic'

learning:
optimizer_name : 'momentum' # Chosen from [sgd, momentum, adam, rmsprop]
save_optimizer : True # Whether to save the optimizer parameters into the checkpoint file.
learning_rate_init : 0.0001
lr_type : 'piecewise' # Chosen from [exponential, piecewise]
lr_decay_epoch : 5 # Epochs after which learning rate decays. Int or float. Used when chosen `exponential` lr_type.
lr_decay_factor : 0.96 # The learning rate decay factor. Used when chosen `exponential` lr_type.
lr_lower_bound : 0.000001 # The minimum learning rate.
pw_boundaries : [30, 50] # epoch based boundaries
pw_values : [0.0001, 0.00003, 0.00001] # FIRST VALUE MUST BE LEARNING_RATE_INIT

validation:
# nms
nms_threshold : 0.45 # iou threshold in nms operation
score_threshold : 0.01 # threshold of the prob of the classes in nms operation, i.e. score = pred_confs * pred_probs.
nms_topk : 150 # keep at most nms_topk outputs after nms

# mAP eval
eval_threshold : 0.5 # the iou threshold applied in mAP evaluation
Binary file added data/frame_level/frame001out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ sqlalchemy
pandas==0.24.2
python-crontab>=2.3.8, <3.0
seaborn>=0.9
tqdm==4.33.0
33 changes: 33 additions & 0 deletions src/run_transfer_learning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from traffic_analysis.d00_utils.load_confs import load_paths, load_credentials, \
load_parameters, load_training_parameters
from traffic_analysis.d04_modelling.transfer_learning.training_data_loader import TrainingDataLoader, TransferDataset
from traffic_analysis.d04_modelling.transfer_learning.train_tensorflow_model import transfer_learn

paths = load_paths()
creds = load_credentials()
params = load_parameters()
train_params = load_training_parameters()

training_data_loader = TrainingDataLoader(datasets=[TransferDataset.cvat, TransferDataset.detrac],
creds=creds,
paths=paths)

fraction_for_training = 0.8
x_train, y_train, x_test, y_test = training_data_loader.get_train_and_test(fraction_for_training)


saved_text_files_dir = paths['temp_annotation']
with open(saved_text_files_dir + 'train.txt', 'w') as f:
for item in y_train:
f.write("%s\n" % item)

with open(saved_text_files_dir + 'test.txt', 'w') as f:
for item in y_test:
f.write("%s\n" % item)

transfer_learn(paths=paths,
params=params,
train_params=train_params,
train_file='train.txt',
test_file='test.txt',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems odd to me that we feed in these txt files. Why don't we feed in data?

selected_labels=params['selected_labels'])
6 changes: 6 additions & 0 deletions src/traffic_analysis/d00_utils/load_confs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def load_app_parameters():
return {**params['visualization']}


def load_training_parameters():
with open(project_dir + '/conf/base/training_parameters.yml') as f:
params = yaml.safe_load(f)
return collapse_dict_hierarchy(params)


def load_credentials():

filepath = os.sep.join(
Expand Down
46 changes: 46 additions & 0 deletions src/traffic_analysis/d02_ref/ref_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import subprocess
from subprocess import Popen, PIPE

from traffic_analysis.d00_utils.data_loader_s3 import DataLoaderS3


def upload_json_to_s3(paths: dict,
save_name: str,
Expand Down Expand Up @@ -66,4 +68,48 @@ def get_names_of_folder_content_from_s3(bucket_name, prefix, s3_profile):
end = Time.time()
elapsed_time = end-start

assert ((len(files) == 0) or (files[0] != '')), 'set your aws credentials'

return elapsed_time, files


def get_s3_video_path_from_xml_name(xml_file_name, s3_creds, paths):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have a lot of the ingredients needed here in traffic_analysis.d05_evaluation.chunk_evaluator.ChunkEvaluator. Can we leverage that?


# Supports old and new naming conventions
vals = xml_file_name.split('_')
data_loader_s3 = DataLoaderS3(s3_credentials=s3_creds,
bucket_name=paths['bucket_name'])

if (len(vals) >= 4):
date = vals[1]
file_names = [xml_file_name.split('_')[1:][0].replace('-', '') + '-' +
xml_file_name.split('_')[1:][1].replace('-', '')[:6] + '_' +
xml_file_name.split('_')[1:][2],
xml_file_name.split('_')[1:][0] + ' ' +
xml_file_name.split('_')[1:][1].replace('-', ':') + '_' +
xml_file_name.split('_')[1:][2]]
else:
date = vals[0]
file_names = [xml_file_name.split('_')[0].replace('-', '') + '-' +
xml_file_name.split('_')[1].replace('-', '')[:6] + '_' +
xml_file_name.split('_')[2],
xml_file_name.split('_')[0] + ' ' +
xml_file_name.split('_')[1].replace('-', ':') + '_' +
xml_file_name.split('_')[2]]
file_to_download = paths['s3_video'] + \
date + '/' + \
file_names[0] + '.mp4'

if(data_loader_s3.file_exists(file_to_download)):
return file_to_download

else:
file_to_download = paths['s3_video'] + \
date + '/' + \
file_names[1] + '.mp4'

if (data_loader_s3.file_exists(file_to_download)):
return file_to_download
else:
print('Could not download file: ' + xml_file_name)
return
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from traffic_analysis.d02_ref.ref_utils import get_names_of_folder_content_from_s3
from traffic_analysis.d00_utils.data_loader_s3 import DataLoaderS3
from traffic_analysis.d02_ref.ref_utils import get_s3_video_path_from_xml_name


def upload_annotation_names_to_s3(paths: dict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
remove_overlapping_boxes, letterbox_resize
from traffic_analysis.d04_modelling.transfer_learning.convert_darknet_to_tensorflow import parse_anchors, \
yolov3_darknet_to_tensorflow
from traffic_analysis.d04_modelling.transfer_learning.generate_tensorflow_model import YoloV3
from traffic_analysis.d04_modelling.transfer_learning.tensorflow_model_loader import YoloV3
from traffic_analysis.d04_modelling.perform_detection_opencv import label_detections, \
choose_objects_of_selected_labels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import tensorflow as tf
import numpy as np

from traffic_analysis.d04_modelling.transfer_learning.generate_tensorflow_model import YoloV3
from traffic_analysis.d04_modelling.transfer_learning.tensorflow_model_loader import YoloV3
from traffic_analysis.d02_ref.download_detection_model_from_s3 import download_detection_model_from_s3


Expand Down
Loading