Skip to content

Instantly share code, notes, and snippets.

View tanmayymishra's full-sized avatar
🏠
Working from home

Tanmay Mishra tanmayymishra

🏠
Working from home
View GitHub Profile
model.save('math.h5')
!deepCC math.h5
image = Single_Image_Prediction(valid_gen[0][0][17])
pred_value = model.predict(image)
#print(pred_value)
index_value = np.argmax(pred_value,axis=1) #For categorical model
print("Prediction=",dev[index_value[0]])
image = Single_Image_Prediction(valid_gen[0][0][8])
pred_value = model.predict(image)
#print(pred_value)
index_value = np.argmax(pred_value,axis=1) #For categorical model
print("Prediction=",dev[index_value[0]])
dev= ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'add', 'dec', 'div', 'eq', 'mul', 'sub', 'x', 'y', 'z']
def Single_Image_Prediction(file):
#image = load_img(file, color_mode='rgb', target_size=(128, 128))
image= file
print("Actual Letter")
plt.imshow((image * .255).astype(np.uint8), cmap='gray')
plt.show()
print(image.shape)
# cv.imshow('image',file)
dev= ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'add', 'dec', 'div', 'eq', 'mul', 'sub', 'x', 'y', 'z']
def Single_Image_Prediction(file):
#image = load_img(file, color_mode='rgb', target_size=(128, 128))
image= file
print("Actual Letter")
plt.imshow((image * .255).astype(np.uint8), cmap='gray')
plt.show()
print(image.shape)
# cv.imshow('image',file)
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('Model Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.legend(['Train','Test'], loc= 'upper right');
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title("Model Accuracy")
plt.xlabel("Epoch")
plt.ylabel("Accuracy")
plt.legend(["Train", "Test"], loc= "lower right");
model.compile(optimizer= 'adam', loss= 'categorical_crossentropy', metrics= ['accuracy'])
history= model.fit(train_gen, epochs= 25, validation_data= valid_gen)
model= Sequential([
layers.Conv2D(32, (3,3), activation= 'relu', input_shape= (50,50,1)),
layers.MaxPooling2D(pool_size= (2,2), padding= 'same'),
layers.Dropout(0.2),
layers.Conv2D(16, (3,3), activation= 'relu'),
layers.MaxPooling2D(pool_size= (2,2), padding= 'same'),
layers.Flatten(),
layers.Dense(120, activation= 'relu'),
layers.Dropout(0.2),
layers.Dense(75, activation= 'relu'),
train_dir= './trainn/'
train_datagen= tf.keras.preprocessing.image.ImageDataGenerator(rescale= 1/.255, validation_split= 0.2)
train_gen= train_datagen.flow_from_directory(train_dir, target_size= (50,50), color_mode= 'grayscale', class_mode= 'categorical', batch_size= 32, subset= 'training')
valid_gen= train_datagen.flow_from_directory(train_dir, target_size= (50,50), color_mode= 'grayscale', class_mode= 'categorical', batch_size= 32, subset= 'validation')