Skip to content

Instantly share code, notes, and snippets.

View AmrutaKoshe's full-sized avatar
💭
LIving in quarantine

Amruta Koshe AmrutaKoshe

💭
LIving in quarantine
View GitHub Profile
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)
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)))
score = model.evaluate(val_gen, steps= len(val_gen))
for idx, metric in enumerate(model.metrics_names):
print('{}:{}'.format(metric, score[idx]))
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)))
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()
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))
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
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))
wget -N "https://cainvas-static.s3.amazonaws.com/media/user_data/AmrutaKoshe/gems.zip"
!unzip -qo gems.zip
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