Skip to content

Instantly share code, notes, and snippets.

Avatar

Yuvnish Malhotra Yuvnish017

View GitHub Profile
View test_pipeline_equation.py
def test_pipeline_equation(image_path):
chars = []
img = cv2.imread(image_path)
img = cv2.resize(img, (800, 800))
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# blurred = cv2.GaussianBlur(img_gray, (3, 3), 0)
edged = cv2.Canny(img_gray, 30, 150)
contours = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(contours)
contours = sort_contours(contours, method="left-to-right")[0]
View image_test.py
def test_pipeline(image_path):
img = cv2.imread(image_path)
img = cv2.resize(img, (800, 800))
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# blurred = cv2.GaussianBlur(img_gray, (3, 3), 0)
edged = cv2.Canny(img_gray, 30, 150)
contours = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(contours)
contours = sort_contours(contours, method="left-to-right")[0]
labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'add', 'div', 'mul', 'sub']
View train_model.py
def step_decay(epoch):
initial_learning_rate = 0.001
dropEvery = 10
factor = 0.5
lr = initial_learning_rate*(factor**np.floor((1 + epoch)/dropEvery))
return float(lr)
checkpoint = ModelCheckpoint('maths_symbol_and_digits_recognition.h5',
monitor='val_loss', save_best_only=True,
verbose=1, mode='min')
View building_model.py
def math_symbol_and_digits_recognition(input_shape=(32, 32, 1)):
regularizer = l2(0.01)
model = Sequential()
model.add(Input(shape=input_shape))
model.add(Conv2D(32, (3, 3), strides=(1, 1), padding='same',
kernel_initializer=glorot_uniform(seed=0),
name='conv1', activity_regularizer=regularizer))
model.add(Activation(activation='relu', name='act1'))
model.add(MaxPool2D((2, 2), strides=(2, 2)))
model.add(Conv2D(32, (3, 3), strides=(1, 1), padding='same',
View to_categorical.py
X_train = np.array(X_train)
X_test = np.array(X_test)
Y_train = np.array(Y_train)
Y_test = np.array(Y_test)
Y_train = to_categorical(Y_train)
Y_test = to_categorical(Y_test)
X_train = np.expand_dims(X_train, axis=-1)
X_test = np.expand_dims(X_test, axis=-1)
X_train = X_train/255.
View preprocessing.py
X = []
for i in range(len(x)):
# print(i)
img = x[i]
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
threshold_image = cv2.threshold(img_gray, 0, 255, cv2.THRESH_BINARY_INV|cv2.THRESH_OTSU)[1]
threshold_image = cv2.resize(threshold_image, (32, 32))
X.append(threshold_image)
print(len(X))
@Yuvnish017
Yuvnish017 / test_image2py
Created Jul 10, 2021
Parkinson_disease_detection
View test_image2py
figure = plt.figure(figsize=(2, 2))
img_parkinson = np.squeeze(image_parkinson, axis=0)
plt.imshow(img_parkinson)
plt.axis('off')
plt.title(f'Prediction by the model: {labels[np.argmax(ypred_parkinson[0], axis=0)]}')
plt.show()
@Yuvnish017
Yuvnish017 / test_image1.py
Created Jul 10, 2021
Parkinson_disease_detection
View test_image1.py
figure = plt.figure(figsize=(2, 2))
img_healthy = np.squeeze(image_healthy, axis=0)
plt.imshow(img_healthy)
plt.axis('off')
plt.title(f'Prediction by the model: {labels[np.argmax(ypred_healthy[0], axis=0)]}')
plt.show()
@Yuvnish017
Yuvnish017 / testing.py
Created Jul 10, 2021
Parkinson_disease_detection
View testing.py
labels = ['Healthy', 'Parkinson']
image_healthy = cv2.imread('Parkinson_disease_detection/test_image_healthy.png')
image_parkinson = cv2.imread('Parkinson_disease_detection/test_image_parkinson.png')
image_healthy = cv2.resize(image_healthy, (128, 128))
image_healthy = cv2.cvtColor(image_healthy, cv2.COLOR_BGR2GRAY)
image_healthy = np.array(image_healthy)
image_healthy = np.expand_dims(image_healthy, axis=0)
image_healthy = np.expand_dims(image_healthy, axis=-1)
@Yuvnish017
Yuvnish017 / model_training.py
Created Jul 10, 2021
Parkinson_disease_detection
View model_training.py
hist = model.fit(x_train, y_train, batch_size=128, epochs=70, validation_data=(x_test, y_test))