<jupyter_start><jupyter_text>Building the model<jupyter_code># Loading the ResNet152 architecture with imagenet weights as base
base = tf.keras.applications.ResNet152(include_top=False, weights='imagenet',input_shape=[IMG_SIZE,IMG_SIZE,3])
base.summary()
model = tf.keras.Sequential()
model.add(base)
model.add(BatchNormalization(axis=-1))
model.add(GlobalAveragePooling2D())
model.add(Dense(5, activation='softmax'))
model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer=tf.keras.optimizers.Adamax(learning_rate=0.01), metrics=['acc'])
model.summary()<jupyter_output>Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
resnet152 (Functional)       (None, 7, 7, 2048)        58370944  
_________________________________________________________________
batch_normalization (BatchNo (None, 7, 7, 2048)        8192      
_________________________________________________________________
global_average_pooling2d (Gl (None, 2048)              0         
_________________________________________________________________
dense (Dense)                (None, 5)                 10245     
=================================================================
Total params: 58,389,381
Trainable params: 58,233,861
Non-trainable params: 155,520
_________________________________________________________________<jupyter_text>Loading the trained model<jupyter_code>history = model.fit(
      train_generator,
      steps_per_epoch=BATCH_SIZE,
      epochs=20,
      validation_data=valid_generator,
      batch_size=BATCH_SIZE
      )
model.save('ResNet152.h5')
# Loading the ResNet101 architecture with imagenet weights as base
base = tf.keras.applications.ResNet101(include_top=False, weights='imagenet',input_shape=[IMG_SIZE,IMG_SIZE,3])

model = tf.keras.Sequential()
model.add(base)
model.add(BatchNormalization(axis=-1))
model.add(GlobalAveragePooling2D())
model.add(Dense(5, activation='softmax'))

model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer=tf.keras.optimizers.Adamax(learning_rate=0.01), metrics=['acc'])

history = model.fit(
      train_generator,
      steps_per_epoch=BATCH_SIZE,
      epochs=20,
      validation_data=valid_generator,
      batch_size=BATCH_SIZE
      )

model.save('ResNet101.h5')
# Loading the ResNet50 architecture with imagenet weights as base
base = tf.keras.applications.ResNet50(include_top=False, weights='imagenet',input_shape=[IMG_SIZE,IMG_SIZE,3])

model = tf.keras.Sequential()
model.add(base)
model.add(BatchNormalization(axis=-1))
model.add(GlobalAveragePooling2D())
model.add(Dense(5, activation='softmax'))

model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer=tf.keras.optimizers.Adamax(learning_rate=0.01), metrics=['acc'])

history = model.fit(
      train_generator,
      steps_per_epoch=BATCH_SIZE,
      epochs=20,
      validation_data=valid_generator,
      batch_size=BATCH_SIZE
      )

model.save('ResNet50.h5')
test_img_path = data_path+"test_images/2216849948.jpg"

img = cv2.imread(test_img_path)
resized_img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)).reshape(-1, IMG_SIZE, IMG_SIZE, 3)/255

plt.figure(figsize=(8,4))
plt.title("TEST IMAGE")
plt.imshow(resized_img[0])
preds = []
ss = pd.read_csv(data_path+'sample_submission.csv')

for image in ss.image_id:
    img = tf.keras.preprocessing.image.load_img(data_path+'test_images/' + image)
    img = tf.keras.preprocessing.image.img_to_array(img)
    img = tf.keras.preprocessing.image.smart_resize(img, (IMG_SIZE, IMG_SIZE))
    img = tf.reshape(img, (-1, IMG_SIZE, IMG_SIZE, 3))
    prediction = model.predict(img/255)
    preds.append(np.argmax(prediction))

my_submission = pd.DataFrame({'image_id': ss.image_id, 'label': preds})
my_submission.to_csv('submission.csv', index=False) 
# Submission file ouput
print("Submission File: \n---------------\n")
print(my_submission.head()) # Predicted Output<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15147783251231528, 'fraction_numerical': 0.034482758620689655, 'mean_word_length': 5.63562091503268, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '507458', 'license': 'MIT', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1306, 'n_words': 193, 'path': 'Notebooks/Casava Plant Disease Prediction/Cassava_Plant_Disease.ipynb', 'repo_name': 'Bhagyashri2000/Grokking-Machine-Learning', 'size': '4060'}