Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 60 additions & 0 deletions loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,63 @@ def __init__(self):
print("Training set size: ", len(self.training_dataset))
print("Validation set size: ", len(self.validation_dataset))

def imgs_input_fn(filenames, labels=None, perform_shuffle=False, repeat_count=1, batch_size=1):
def _parse_function(filename, label):
seq = filename[0]
frame = filename[1]

camera1_path = os.path.join(DATASET_DIR, "{:02}".format(seq), "image_0", "{:06}.png".format(frame))
camera2_path = os.path.join(DATASET_DIR, "{:02}".format(seq), "image_1", "{:06}.png".format(frame))
camera1_path_next = os.path.join(DATASET_DIR, "{:02}".format(seq), "image_0", "{:06}.png".format(frame + 1))
camera2_path_next = os.path.join(DATASET_DIR, "{:02}".format(seq), "image_1", "{:06}.png".format(frame + 1))
def get_image(filename):
image_string = tf.read_file(filename)
image = tf.image.decode_image(image_string, channels=1)
image.set_shape([None, None, None])
image = tf.image.resize_images(image, [HEIGHT, WIDTH])
image = tf.subtract(image, 127.5) # Zero-center by mean pixel
image = tf.divide(image, 127.5)
image.set_shape([HEIGHT, WIDTH, 3])
return image

image1 = get_image(camera1_path)
image2 = get_image(camera2_path)
image3 = get_image(camera1_path_next)
image4 = get_image(camera2_path_next)


d = dict([image1, image2, image3, image4]), label
return d

if labels is None:
labels = [0]*len(filenames)
labels=np.array(labels)
# Expand the shape of "labels" if necessory
if len(labels.shape) == 1:
labels = np.expand_dims(labels, axis=1)
filenames = tf.constant(filenames)
labels = tf.constant(labels)
labels = tf.cast(labels, tf.float32)
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
dataset = dataset.map(_parse_function)
if perform_shuffle:
# Randomizes input using a window of 256 elements (read into memory)
dataset = dataset.shuffle(buffer_size=256)
dataset = dataset.repeat(repeat_count) # Repeats dataset this # times
dataset = dataset.batch(batch_size) # Batch size to use
iterator = dataset.make_one_shot_iterator()
batch_features, batch_labels = iterator.get_next()
return batch_features, batch_labels

def get_dataset(self):
imgs = []
labels = []
for data in self.training_dataset:
imgs.append(data.get_loc())
labels.append(data.get_matrix())
return imgs_input_fn(imgs,labels)


def visualize(self, dataset):
plot_numbers = [[], [], [], [], [], []]
for data in dataset:
Expand Down Expand Up @@ -183,6 +240,9 @@ def __init__(self, sequence_id, frame_id, matrix1, matrix2):
v = self.rotationMatrixToEulerAngles(rotation[:3,:3])
self.matrix = np.array([self.translation_mat[0], self.translation_mat[1], self.translation_mat[2], v[0], v[1], v[2]])

def get_loc(self):
return [self.sequence_id, self.frame_id]

def get_matrix(self):
return self.matrix

Expand Down
5 changes: 4 additions & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def train(self, dataset, epochs, iterations, batch_size):
with tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)):
opt = optimizer.minimize(loss)

saver = tf.train.Saver(max_to_keep=10000)
saver = tf.train.Saver(tf.global_variables(), max_to_keep=10000)

idx = 0
while(os.path.exists(os.path.join(LOG_DIR, "egomotion" +str(idx)))):
Expand All @@ -63,6 +63,9 @@ def train(self, dataset, epochs, iterations, batch_size):
sess = tf.Session(config=config)
sess.run(tf.global_variables_initializer())

batch = dataset.get_dataset()
first_batch = sess.run(batch)
print(first_batch)
for epoch in range(epochs):

for iter in range(iterations):
Expand Down