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
''' | |
# Baseline script by Supreet Manyam (Ziron) | |
''' | |
import pandas as pd | |
import numpy as np | |
import gc | |
train = pd.read_csv("data/train.csv", |
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 tensorflow as tf | |
x = tf.constant([1,2,3,4,5]) | |
y = tf.constant([1,1,1,1,1]) | |
a = tf.add(x,y) | |
print(a) |
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
try: | |
# %tensorflow_version only exists in Colab. | |
%tensorflow_version 2.x | |
except Exception: | |
pass |
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
# TensorFlow and tf.keras | |
import tensorflow as tf | |
from tensorflow import keras | |
# Helper libraries | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from tqdm import tqdm | |
from keras.preprocessing import image |
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 google.colab import drive | |
drive.mount('/content/drive') |
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
!unzip /content/drive/My\ Drive/train_LbELtWX.zip | |
train = pd.read_csv('train.csv') |
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
# We have grayscale images, so while loading the images we will keep grayscale=True, if you have RGB images, you should set grayscale as False | |
train_image = [] | |
for i in tqdm(range(train.shape[0])): | |
img = image.load_img('train/'+train['id'][i].astype('str')+'.png', target_size=(28,28,1), color_mode="grayscale") | |
img = image.img_to_array(img) | |
img = img/255 | |
train_image.append(img) | |
X = np.array(train_image) | |
# Preprocessing the Target |
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
# Create Train and validation data to check the performance at each epoch | |
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, test_size=0.2) | |
# Using Keras Sequential API to add neural network layers | |
model = keras.Sequential() | |
model.add(keras.layers.Conv2D(32, kernel_size=(3, 3),activation='relu',input_shape=(28,28,1))) | |
model.add(keras.layers.Conv2D(64, (3, 3), activation='relu')) | |
model.add(keras.layers.MaxPooling2D(pool_size=(2, 2))) | |
model.add(keras.layers.Dropout(0.25)) | |
model.add(keras.layers.Flatten()) |
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']) | |
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test)) |
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
# unzip the test file to read images | |
!unzip /content/drive/My\ Drive/test_ScVgIM0.zip | |
# Read test file names | |
test = pd.read_csv('test.csv') | |
test_copy = test.copy() | |
# Read test images and preprocess | |
test_image = [] | |
for i in tqdm(range(test.shape[0])): |
OlderNewer