This file contains hidden or 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 os | |
import gc | |
import time | |
import psutil | |
from keras.preprocessing.image import ImageDataGenerator | |
from gapcv.vision import Images |
This file contains hidden or 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
MB = (1024 * 1024) | |
GB = (MB * 1024) | |
start_mem = psutil.virtual_memory().used | |
print("Start Memory: %.2f GB" % (start_mem / GB)) |
This file contains hidden or 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 Preprocessing | |
start_time = time.time() | |
dataset = Images('flowers', 'flowers', config=['resize=(128,128)', 'store']) | |
print("Preprocessing: ", int(time.time() - start_time), "secs") | |
print("Classes", dataset.classes, "Images:", dataset.count) | |
curr_mem = psutil.virtual_memory().used |
This file contains hidden or 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
STEPS = 1000 | |
print("Keras: Flow") | |
datagen = ImageDataGenerator() | |
start_time = time.time() | |
datagen.fit(X_train) | |
train_generator = datagen.flow(X_train, Y_train, batch_size=32) |
This file contains hidden or 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
STEPS = 1000 | |
print("Gap: Flow") | |
start_mem = psutil.virtual_memory().used | |
start_time = time.time() | |
dataset.minibatch = 32 | |
train_generator = dataset.minibatch | |
print("PRE-TIME", time.time() - start_time) |
This file contains hidden or 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
Keras: Flow | Gap: Flow | ||
---|---|---|---|
PRE-TIME | 0.38779211044311523 | 1.8835067749023438e-05 | |
TIME | 1.3482673168182373 | 0.7792487144470215 | |
Memory Used: | 1.79 GB | -0.00 GB |
This file contains hidden or 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
print("Keras: flow_from_directory") | |
start_mem = psutil.virtual_memory().used | |
start_time = time.time() | |
datagen = ImageDataGenerator(rescale=1./255) | |
train_generator = datagen.flow_from_directory('flowers', target_size=(128,128), batch_size=32) | |
print("PRE-TIME", time.time() - start_time) | |
start_time = time.time() |
This file contains hidden or 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
print("Gap: flow from directory") | |
start_mem = psutil.virtual_memory().used | |
start_time = time.time() | |
dataset = Images(config=['stream']) | |
dataset.load('flowers') | |
dataset.minibatch = 32 | |
train_generator = dataset.minibatch |
This file contains hidden or 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
Keras: flow_from_directory | Gap: flow from directory | ||
---|---|---|---|
PRE-TIME | 0.20801329612731934 | 0.01245427131652832 | |
TIME | 89.3897156715393 | 6.902476787567139 | |
Memory Used: | 0.00 GB | -0.00 GB |
This file contains hidden or 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
print("Keras: Flow with Augmentation") | |
datagen = ImageDataGenerator(rotation_range=30) | |
start_time = time.time() | |
datagen.fit(X_train) | |
train_generator = datagen.flow(X_train, Y_train, batch_size=32) | |
print("PRE-TIME (fit)", time.time() - start_time) |
OlderNewer