<jupyter_start><jupyter_text>Normalize the data<jupyter_code>x_train = x_train / 255.0
print("x_train shape: ",x_train.shape)
from sklearn.preprocessing import LabelEncoder
label_encoder = LabelEncoder()
y_train = train_df.iloc[:train_size, 1]
# Drop 'Id' column
X_train = train_df.drop(labels = ["Id"], axis = 1)
y_train = label_encoder.fit_transform(y_train)
y_train.shape
from keras.utils.np_utils import to_categorical
y_train = to_categorical(y_train, num_classes = 5005)
y_train.shape
print(y_train)
from keras.utils.np_utils import to_categorical # convert to one-hot-encoding
from keras.models import Sequential # to create a cnn model
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D
from keras.optimizers import RMSprop,Adam
from keras.layers.normalization import BatchNormalization
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ReduceLROnPlateau
model = Sequential()

model.add(Conv2D(filters = 16, kernel_size = (5,5), padding = 'Same', activation = 'relu', input_shape = (100,100,3)))
model.add(Conv2D(filters = 16, kernel_size = (5,5), padding = 'Same', activation = 'relu'))
model.add(MaxPool2D(pool_size = (2,2)))
model.add(Dropout(0.25))

model.add(Conv2D(filters = 32, kernel_size = (3,3), padding = 'Same', activation = 'relu'))
model.add(Conv2D(filters = 32, kernel_size = (3,3), padding = 'Same', activation = 'relu'))
model.add(MaxPool2D(pool_size = (2,2), strides=(2,2)))
model.add(Dropout(0.25))

model.add(Conv2D(filters = 64, kernel_size = (3,3), padding = 'Same', activation = 'relu'))
model.add(Conv2D(filters = 64, kernel_size = (3,3), padding = 'Same', activation = 'relu'))
model.add(MaxPool2D(pool_size = (2,2), strides=(2,2)))
model.add(Dropout(0.25))

# fully connected
model.add(Flatten())
model.add(Dense(256, activation = 'relu'))
model.add(BatchNormalization())
model.add(Dense(y_train.shape[1], activation = "softmax"))
model.summary()
# Define the optimizer
optimizer = Adam(lr=0.001, beta_1=0.9, beta_2 = 0.999)
# set a learning rate annealer
learning_rate_reduction = ReduceLROnPlateau(monitor='var_acc',
                                           patience = 3, 
                                           verbose = 1, 
                                           factor = 0.5,
                                           min_lr = 0.00001)
model.compile(optimizer = optimizer, loss = "categorical_crossentropy", metrics=["accuracy"])<jupyter_output><empty_output><jupyter_text>Data augmentation Epoch and Batch size<jupyter_code>epochs = 10
batch_size = 1000
history = model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size, verbose=2, callbacks=[learning_rate_reduction])<jupyter_output>Epoch 1/10
{'fraction_non_alphanumeric': 0.13229859571322986, 'fraction_numerical': 0.03954175905395418, 'mean_word_length': 4.581443298969072, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '594994', 'license': 'MIT', 'n_tokens_mistral': 979, 'n_tokens_neox': 914, 'n_words': 196, 'path': 'Kaggle Humpback Whale Identification/Whale_recognition (1).ipynb', 'repo_name': 'RajeshreeKale/PROJECTS', 'size': '2706'}