<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
import shutil
import re
import random
import seaborn as sns
import cv2 as cv
from PIL import Image
import pickle
import sys
sys.setrecursionlimit(1000000000)

import tensorflow as tf
from tensorflow.keras.preprocessing.image import load_img, img_to_array
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.preprocessing import image_dataset_from_directory
# from tfhub import load_model_weights
!unzip /content/drive/MyDrive/Hackathon/dataset-resized.zip -d /content/
from google.colab import drive
drive.mount('/content/drive')
os.listdir(os.path.join(os.getcwd(),"dataset-resized"))
## get a path to the folder with images
path = os.path.join(os.getcwd(),"dataset-resized")
path
print(len(os.listdir('./dataset-resized//')))
train = tf.keras.preprocessing.image_dataset_from_directory(path, batch_size=16, image_size=(224,224), shuffle=True, label_mode='categorical', validation_split = 0.25, seed = 1, subset = 'training')
valid = tf.keras.preprocessing.image_dataset_from_directory(path, batch_size=16, image_size=(224,224), shuffle=True, label_mode='categorical', validation_split = 0.25, seed = 1, subset = 'validation')
model = tf.keras.applications.ResNet50(include_top=False, input_shape=(224,224,3))
model.summary()
def waste_segment():
    model2 = tf.keras.Sequential()
    model = tf.keras.applications.ResNet50(include_top=False, input_shape=(224,224,3), weights='imagenet')
    model2.add(model)
    model2.add(tf.keras.layers.Flatten())
    model2.add(tf.keras.layers.Dense(6, activation='softmax'))
    return model2
model2 = tf.keras.Sequential()
model2.add(model)
model2.add(tf.keras.layers.Flatten())
model2.add(tf.keras.layers.Dropout(0.2))
model2.add(Dense(512, activation = 'relu'))
model2.add(tf.keras.layers.Dropout(0.2))
model2.add(Dense(256, activation = 'relu'))
model2.add(tf.keras.layers.Dropout(0.2))
model2.add(Dense(128, activation = 'relu'))
model2.add(tf.keras.layers.Dropout(0.2))
model2.add(Dense(64, activation = 'relu'))
model2.add(tf.keras.layers.Dropout(0.2))
model2.add(tf.keras.layers.Dense(7, activation='softmax'))
# model2.load_weights('/content/drive/MyDrive/waste segmentation/waste_weights.h5')
model2.summary()
model2.compile(optimizer=tf.keras.optimizers.Adam(), loss = tf.keras.losses.CategoricalCrossentropy(), metrics = ['accuracy'])
model2.fit(x=train, validation_data=valid, epochs = 10)
while(1):
  pass
temp = img_to_array(load_img('/content/dataset-resized/cardboard/cardboard100.jpg', target_size=(224,224))).reshape(1,224,224,3)
np.argmax(model2.predict(temp))

model2.save_weights('waste_weights_heavy.h5')
!cp waste_weights_heavy.h5 /content/drive/MyDrive/Hackathon/waste_weights_heavy.h5<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1416114405301709, 'fraction_numerical': 0.04325078479246599, 'mean_word_length': 6.206030150753769, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '75474', 'license': 'Apache-2.0', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1047, 'n_words': 168, 'path': 'model/v3_waste_segregation.ipynb', 'repo_name': 'H4R5H1T-007/Waste-Segregation', 'size': '2867'}