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
fc_layer_size = 256 | |
img_size = IMG_SIZE | |
conv_inputs = keras.Input(shape=(img_size[1], img_size[0],3), name='ani_image') | |
conv_layer = layers.Conv2D(128, kernel_size=3, activation='relu')(conv_inputs) | |
conv_layer = layers.MaxPool2D(pool_size=(2,2))(conv_layer) | |
conv_layer = layers.Conv2D(128, kernel_size=3, activation='relu')(conv_layer) | |
conv_layer = layers.MaxPool2D(pool_size=(2,2))(conv_layer) |
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
cat_quantity = sum(labels_valid) | |
for i in range(1,10): | |
print('threshold :'+str(.1*i)) | |
print(sum(labels_valid[preds > .1*i])/labels_valid[preds > .1*i].shape[0]) |
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
fc_layer_size = 256 | |
img_size = IMG_SIZE | |
conv_inputs = keras.Input(shape=(img_size[1], img_size[0],3), name='ani_image') | |
#first convolutional layer. | |
conv_layer = layers.Conv2D(48, kernel_size=3, activation='relu')(conv_inputs) | |
conv_layer = layers.MaxPool2D(pool_size=(2,2))(conv_layer) | |
#second convolutional layer. | |
conv_layer = layers.Conv2D(48, kernel_size=3, activation='relu')(conv_layer) | |
conv_layer = layers.MaxPool2D(pool_size=(2,2))(conv_layer) |
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
preds = conv_model.predict(x_valid) | |
preds = np.asarray([pred[0] for pred in preds]) | |
np.corrcoef(preds, labels_valid)[0][1] # 0.15292172 |
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
fc_layer_size = 128 | |
img_size = IMG_SIZE | |
conv_inputs = keras.Input(shape=(img_size[1], img_size[0],3), name='ani_image') | |
conv_layer = layers.Conv2D(24, kernel_size=3, activation='relu')(conv_inputs) | |
conv_layer = layers.MaxPool2D(pool_size=(2,2))(conv_layer) | |
conv_x = layers.Flatten(name = 'flattened_features')(conv_layer) #turn image to vector. | |
conv_x = layers.Dense(fc_layer_size, activation='relu', name='first_layer')(conv_x) | |
conv_x = layers.Dense(fc_layer_size, activation='relu', name='second_layer')(conv_x) |
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
customAdam = keras.optimizers.Adam(lr=0.001) | |
model.compile(optimizer=customAdam, # Optimizer | |
# Loss function to minimize | |
loss="mean_squared_error", | |
# List of metrics to monitor | |
metrics=["binary_crossentropy","mean_squared_error"]) | |
print('# Fit model on training data') | |
history = model.fit(x_train, |
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
from tensorflow import keras | |
from tensorflow.keras import layers | |
total_pixels = img_size[0] *img_size[1] * 3 | |
fc_size = 512 | |
inputs = keras.Input(shape=(img_size[1], img_size[0],3), name='ani_image') | |
x = layers.Flatten(name = 'flattened_img')(inputs) #turn image to vector. | |
x = layers.Dense(fc_size, activation='relu', name='first_layer')(x) |
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
SAMPLE_SIZE = 2048 | |
print("loading training cat images...") | |
cat_train_set = np.asarray([pixels_from_path(cat) for cat in glob.glob('cats/*')[:SAMPLE_SIZE]]) | |
print("loading training dog images...") | |
dog_train_set = np.asarray([pixels_from_path(dog) for dog in glob.glob('dogs/*')[:SAMPLE_SIZE]]) | |
valid_size = 512 | |
print("loading validation cat images...") | |
cat_valid_set = np.asarray([pixels_from_path(cat) for cat in glob.glob('cats/*')[-valid_size:]]) | |
print("loading validation dog 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
IMG_SIZE = (94, 125) | |
def pixels_from_path(file_path): | |
im = Image.open(file_path) | |
im = im.resize(IMG_SIZE) | |
np_im = np.array(im) | |
#matrix of pixel RGB values | |
return np_im |
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
shape_counts = defaultdict(int) | |
for i, cat in enumerate(glob.glob('cats/*')[:1000]): | |
if i%100==0: | |
print(i) | |
img_shape = pixels_from_path(cat).shape #loads image as np matrix and checks shape. | |
shape_counts[str(img_shape)]= shape_counts[str(img_shape)]+ 1 | |
shape_items = list(shape_counts.items()) | |
shape_items.sort(key = lambda x: x[1]) | |
shape_items.reverse() |