Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import tensorflow as tf | |
import os | |
import numpy as np | |
from PIL import Image | |
import matplotlib.pyplot as plt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_labels_from_file(data_root, label_path): | |
data = pd.read_csv(label_path) | |
data['fn'] = data.id.map(lambda x: os.path.join( | |
data_root, 'train', x + '.jpg')) | |
int_to_breed = data.breed.unique() | |
breed_to_int = dict((v, k) for k, v in enumerate(int_to_breed)) | |
data['int_breed'] = data.breed.map(lambda x: breed_to_int[x]) | |
return data.fn, data.int_breed, int_to_breed, breed_to_int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_root = './data/all' | |
label_path = './data/all/labels.csv' | |
filenames, labels, int_to_breed, breed_to_int = read_labels_from_file(data_root, label_path) | |
list(zip(*(filenames, labels)))[:5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def one_shot_input_fn(filenames, labels): | |
dataset = tf.data.Dataset.from_tensor_slices( | |
(filenames, labels)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image = tf.placeholder(tf.float32, [None, 224, 224, 3]) | |
label = tf.placeholder(tf.int64, [None]) | |
loss, train_op = SomeNetwork(image, label) | |
with tf.Session() as sess: | |
processed_image, processed_label = get_data_from_file() | |
loss, _ = sess.run( | |
[loss, train_op], | |
feed_dict={image: processed_image, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dataset = dataset.map(_parse_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dataset = dataset.batch(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iterator = dataset.make_one_shot_iterator() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img, label = iterator.get_next() | |
return img, label |
OlderNewer