Skip to content

Commit

Permalink
oxford dataset ready to train
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavz committed Jan 26, 2018
1 parent bbcf6b9 commit 62a6f5a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions egohands_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def create_label_map():
f = open(label_map,"w")
f.write("item {\n id: 1\n name: 'hand'\n}")
f.close()
print("> created ",label_map)

def final_finish():
cwd = os.getcwd()
Expand Down
10 changes: 5 additions & 5 deletions howto_tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
# From the tensorflow/models/research directory
python object_detection/train.py \
--logtostderr \
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/ssd_mobilehandsnet.config \
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/ssd_mobilehandsnet_train.config \
--train_dir=/home/gustav/workspace/deeptraining_hands/model/train

## EVALUATION TENSORFLOW
# From the tensorflow/models/research directory
python object_detection/eval.py \
--logtostderr \
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/ssd_mobilehandsnet.config \
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/ssd_mobilehandsnet_train.config \
--checkpoint_dir=/home/gustav/workspace/deeptraining_hands/model/train \
--eval_dir=/home/gustav/workspace/deeptraining_hands/model/eval

Expand All @@ -29,9 +29,9 @@ tensorboard --logdir=/home/gustav/workspace/deeptraining_hands/model
# From the tensorflow/models/research directory
python object_detection/export_inference_graph.py \
--input_type=image_tensor \
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/faster_rcnn_lowproposalhandsnet.config \
--trained_checkpoint_prefix /home/gustav/workspace/deeptraining_hands/model/train/model.ckpt-200000 \
--output_directory=/home/gustav/workspace/deeptraining_hands/model/frozen_model
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/ssd_mobilehandsnet_train.config \
--trained_checkpoint_prefix /home/gustav/workspace/deeptraining_hands/model/train/model.ckpt-149406 \
--output_directory=/home/gustav/workspace/deeptraining_hands/model/train/frozen_model_149


#### Options for the model.config file ####
Expand Down
37 changes: 32 additions & 5 deletions mat_to_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def read_mat_file(filepath, filename,IMG_FILES_PATH, XML_FILES_PATH):

mat_data = sio.loadmat(filepath)
hand_pos = [] # To store the hand positions in an image

old_pts = []
curr_pts = []
#For all hands in the image align the bounding box to an axis
for i in range(len(mat_data['boxes'][0])):
xmin = float('inf')
Expand All @@ -95,7 +96,8 @@ def read_mat_file(filepath, filename,IMG_FILES_PATH, XML_FILES_PATH):
ymax = -1

for j in range(4):
x, y = mat_data['boxes'][0][i][0][0][j][0]
y, x = mat_data['boxes'][0][i][0][0][j][0]
curr_pts.append(make_int([x,y]))
if xmin > x:
xmin = x
if ymin > y:
Expand All @@ -104,8 +106,12 @@ def read_mat_file(filepath, filename,IMG_FILES_PATH, XML_FILES_PATH):
xmax = x
if ymax < y:
ymax = y

old_pts.append(curr_pts)
hand_pos.insert(0, [xmin, ymin, xmax, ymax])

img_filename = filename.split('.')[0] + '.jpg'
image = IMG_FILES_PATH + '/' + img_filename
visualize(image,old_pts,hand_pos,filename,1)

# Create the XML file
create_xml_file(hand_pos, filename,IMG_FILES_PATH, XML_FILES_PATH)
Expand Down Expand Up @@ -152,13 +158,32 @@ def create_xml_file(hand_pos, filename,IMG_FILES_PATH, XML_FILES_PATH):
rough_xml = et.tostring(root, 'utf-8')
rough_xml = minidom.parseString(rough_xml)
pretty_xml = rough_xml.toprettyxml()
#print(pretty_xml)

# Save the XML file
xml_path = join(XML_FILES_PATH, xml_filename)
with open(xml_path, 'w') as xml_file:
xml_file.write(pretty_xml)


def visualize(image,pts,boxes,filename,time):
font = cv2.FONT_HERSHEY_SIMPLEX
img = cv2.imread(image)

for pt in pts:
pt = np.array(pt)
cv2.polylines(img,[pt], True, (0, 0, 255), 2)
for box in boxes:
xmin, ymin, xmax, ymax = make_int(box)
cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2)

cv2.putText(img, filename, (0,20), font, 0.75, (77, 255, 9), 2)
cv2.imshow('label_check', img)
cv2.waitKey(time)

def make_int(box):
newbox = []
for pt in box:
newbox.append(int(pt))
return newbox


def main():
Expand All @@ -175,12 +200,14 @@ def main():
# List all files in the MAT_FILES_PATH and ignore hidden files (.DS_STORE for Macs)
mat_files = [[join(MAT_FILES_PATH, x), x] for x in os.listdir(MAT_FILES_PATH) if isfile(join(MAT_FILES_PATH, x)) and x[0] is not '.']
mat_files.sort()

# Iterate through all files and convert them to XML
for mat_file in mat_files:
#print(mat_file)
read_mat_file(mat_file[0], mat_file[1],IMG_FILES_PATH, XML_FILES_PATH)
#break
print ("successfully converted {}-labels from mat to pascal-xml").format(directory)
cv2.destroyAllWindows()

if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ train_input_reader: {
}

eval_config: {
num_examples: 480
num_examples: 1
eval_interval_secs: 600
# Note: The below line limits the evaluation process to 10 evaluations.
# Remove the below line to evaluate indefinitely.
# max_evals: 10
visualization_export_dir: "/home/gustav/workspace/deeptraining_hands/model/eval/visualization"
# visualization_export_dir: "/home/gustav/workspace/deeptraining_hands/model/eval/visualization"
}

eval_input_reader: {
Expand Down
1 change: 1 addition & 0 deletions oxfordhands_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def create_label_map():
f = open(label_map,"w")
f.write("item {\n id: 1\n name: 'hand'\n}")
f.close()
print("> created ",label_map)

def cleanup_structure(data_path, dataset_path, tarfile_path):
check = []
Expand Down

0 comments on commit 62a6f5a

Please sign in to comment.