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
model.compile(optimizer='adam', | |
loss='categorical_crossentropy', | |
metrics=['accuracy']) | |
history = model.fit(train_generator, validation_data=valid_generator, | |
steps_per_epoch=train_generator.n//train_generator.batch_size, | |
validation_steps=valid_generator.n//valid_generator.batch_size, | |
epochs=120) |
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
model = Sequential() | |
model.add(Conv2D(filters=32, kernel_size=(3,3),input_shape=(100,100,3), activation='relu', padding = 'same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(filters=64, kernel_size=(3,3), activation='relu', padding = 'same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(filters=64, kernel_size=(3,3), activation='relu', padding = 'same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) |
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
score = model.evaluate(val_gen, steps= len(val_gen)) | |
for idx, metric in enumerate(model.metrics_names): | |
print('{}:{}'.format(metric, score[idx])) |
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
model = Sequential() | |
model.add(Conv2D(filters=32, kernel_size=(3,3),input_shape=(100,100,3), activation='relu', padding = 'same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(filters=64, kernel_size=(3,3), activation='relu', padding = 'same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(filters=64, kernel_size=(3,3), activation='relu', padding = 'same')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) |
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
train_datagen = ImageDataGenerator(vertical_flip=True, | |
horizontal_flip=True, | |
rotation_range=40, | |
width_shift_range=0.2, | |
height_shift_range=0.2, | |
zoom_range=0.1, | |
validation_split=0.2) | |
val_datagen = ImageDataGenerator() |
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
from sklearn.model_selection import train_test_split | |
X_train, X_val, y_train, y_val = train_test_split(Train_Imgs, Train_Lbls, shuffle = True, test_size = 0.2, random_state = 42) | |
print('Shape of X_train: {}, y_train: {} '.format(X_train.shape, y_train.shape)) | |
print('Shape of X_val: {}, y_val: {} '.format(X_val.shape, y_val.shape)) |
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_images(): | |
Images, Labels = [], [] | |
for root, dirs, files in os.walk('gems/train/'): | |
f = os.path.basename(root) # get class name - Amethyst, Onyx, etc | |
for file in files: | |
Labels.append(f) | |
try: | |
image = cv2.imread(root+'/'+file) # read the image (OpenCV) | |
image = cv2.resize(image,(int(img_w), int(img_h))) # resize the image (images are different sizes) | |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # converts an image from BGR color space to RGB |
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
Name=[] | |
for file in os.listdir(directory): | |
Name+=[file] | |
gems_map = dict(zip(Name, [t for t in range(len(Name))])) | |
print(gems_map) | |
r_gems_map=dict(zip([t for t in range(len(Name))],Name)) | |
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
wget -N "https://cainvas-static.s3.amazonaws.com/media/user_data/AmrutaKoshe/gems.zip" | |
!unzip -qo gems.zip |
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 numpy as np | |
import tensorflow as tf | |
from tensorflow import keras | |
from tensorflow.keras import layers | |
import pandas as pd | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
import wget | |
import os | |
import cv2 |
NewerOlder