Skip to content

Commit

Permalink
visualization changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavz committed Jan 29, 2018
1 parent 62a6f5a commit 2e7a890
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
15 changes: 15 additions & 0 deletions howto_tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ python object_detection/train.py \
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/ssd_mobilehandsnet_train.config \
--train_dir=/home/gustav/workspace/deeptraining_hands/model/train

python object_detection/train.py \
--logtostderr \
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/frcnni_handsnet.config \
--train_dir=/home/gustav/workspace/deeptraining_hands/model/train



## EVALUATION TENSORFLOW
# From the tensorflow/models/research directory
python object_detection/eval.py \
Expand All @@ -22,6 +29,14 @@ python object_detection/eval.py \
--checkpoint_dir=/home/gustav/workspace/deeptraining_hands/model/train \
--eval_dir=/home/gustav/workspace/deeptraining_hands/model/eval

python object_detection/eval.py \
--logtostderr \
--pipeline_config_path=/home/gustav/workspace/deeptraining_hands/model/frcnni_handsnet.config \
--checkpoint_dir=/home/gustav/workspace/deeptraining_hands/model/train \
--eval_dir=/home/gustav/workspace/deeptraining_hands/model/eval



## TENSORBOARD
tensorboard --logdir=/home/gustav/workspace/deeptraining_hands/model

Expand Down
2 changes: 1 addition & 1 deletion model/ssd_mobilehandsnet_train.config
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ train_input_reader: {
}

eval_config: {
num_examples: 1
num_examples: 821
eval_interval_secs: 600
# Note: The below line limits the evaluation process to 10 evaluations.
# Remove the below line to evaluate indefinitely.
Expand Down
27 changes: 24 additions & 3 deletions xml_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import glob
import pandas as pd
import xml.etree.ElementTree as ET
import cv2


def xml_to_csv(path):
def xml_to_csv(xml_path,img_path):
xml_list = []
for xml_file in glob.glob(path + '/*.xml'):
for xml_file in glob.glob(xml_path + '/*.xml'):
tree = ET.parse(xml_file)
root = tree.getroot()
boxes = []
for member in root.findall('object'):
value = (root.find('filename').text,
int(root.find('size')[0].text),
Expand All @@ -25,17 +27,36 @@ def xml_to_csv(path):
int(member[4][3].text)
)
xml_list.append(value)
boxes.append(list(value[4:]))
name = str(value[0])

image = img_path + '/' + name
visualize(image,boxes,name,1)

column_name = ['filename', 'width', 'height', 'class', 'xmin', 'ymin', 'xmax', 'ymax']
xml_df = pd.DataFrame(xml_list, columns=column_name)
return xml_df

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

for box in boxes:
xmin, ymin, xmax, ymax = box
cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2)

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

def main():
for directory in ['train','eval']:
xml_path = os.path.join(os.getcwd(), 'data/{}/annotations/xml'.format(directory))
xml_df = xml_to_csv(xml_path)
img_path = os.path.join(os.getcwd(), 'data/{}/images'.format(directory))
xml_df = xml_to_csv(xml_path,img_path)
xml_df.to_csv('data/{}_labels.csv'.format(directory,directory), index=None)
print('Successfully converted {} xml to csv.').format(directory)
cv2.destroyAllWindows()


if __name__ == '__main__':
Expand Down

0 comments on commit 2e7a890

Please sign in to comment.