Skip to content

Instantly share code, notes, and snippets.

@weklund
Created November 13, 2018 13:47
Show Gist options
  • Save weklund/c824b4dca3cd3e78a40a159a504dbeca to your computer and use it in GitHub Desktop.
Save weklund/c824b4dca3cd3e78a40a159a504dbeca to your computer and use it in GitHub Desktop.
def path_to_tensor(path):
img = image.load_img(path, target_size = (224,224))
x= image.img_to_array(img)
return np.expand_dims(x, axis=0)
def paths_to_tensor(paths):
list_of_tensors = [path_to_tensor(path) for path in tqdm(paths)]
return np.vstack(list_of_tensors)
train_tensors = paths_to_tensor(train_files).astype('float32')/255
valid_tensors = paths_to_tensor(valid_files).astype('float32')/255
test_tensors = paths_to_tensor(test_files).astype('float32')/255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment