<jupyter_start><jupyter_text><jupyter_code>!pip install -q kaggle
!mkdir ~/.kaggle
!cp kaggle.json ~/.kaggle/
!chmod 600 ~/.kaggle/kaggle.json
!kaggle datasets download -d kmader/food41
!mkdir food
!unzip food41.zip -d food
import os
for i in os.listdir('food'):
  if '.h5' in i:
    os.remove('food/' + i)
foods = ['cheesecake', 'chicken_curry', 'donuts', 'french_fries', 'fried_rice',
         'omelette', 'pizza', 'samosa', 'grilled_cheese_sandwich', 'ice_cream']
import shutil
for i in os.listdir('food/images'):
  if i in foods:
    continue
  else:
    shutil.rmtree('food/images/' + i)
import cv2
from google.colab.patches import cv2_imshow
img = cv2.imread('/content/food/images/fried_rice/1008935.jpg')
cv2_imshow(cv2.resize(img, (300, 300)))
print(img.shape)
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dropout, AveragePooling2D
from tensorflow.keras.layers import Dense,Flatten
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras import activations
from tensorflow.keras import layers
import numpy as np
import pandas as pd
import cv2
from keras.preprocessing.image import ImageDataGenerator
image_data = ImageDataGenerator(rescale = 1./255,
                                      shear_range = 0.1,
                                      zoom_range = 0.2,
                                      #rotation_range = 30,
                                      #horizontal_flip = True,
                                      validation_split = 0.2)
train_generator = image_data.flow_from_directory("/content/food/images",
                                                       target_size = (300, 300),
                                                       batch_size = 32,
                                                       class_mode = 'categorical',
                                                       subset = 'training')
test_generator = image_data.flow_from_directory("/content/food/images",
                                                    target_size = (300, 300),
                                                    batch_size = 32,
                                                    class_mode ='categorical',                                          
                                                    subset = 'validation')
from tensorflow.keras.applications.resnet50 import ResNet50
import tensorflow as tf
from tensorflow.keras import models
from tensorflow.keras import layers
from tensorflow.keras import optimizers
from tensorflow.keras import regularizers
tl_model = tf.keras.applications.DenseNet201(weights='imagenet', 
                                                     include_top = False, 
                                                     input_shape = (300, 300, 3), 
                                                     pooling='max')
for layer in tl_model.layers[0:-10]:
  layer.trainable = False
tl_model.summary()
model = models.Sequential([tl_model,
                           layers.Dense(1024, activation = 'relu'),
                           layers.Dropout(0.2),
                           layers.Dense(512, activation = 'relu'),
                           layers.Dropout(0.2),
                           layers.Dense(256, activation = 'relu'),
                           layers.Dropout(0.25),
                           layers.Dense(10, activation='softmax')])
from tensorflow.keras.callbacks import ReduceLROnPlateau,EarlyStopping

optimizer = tf.keras.optimizers.Adam(lr = 0.001)
model.compile(loss='categorical_crossentropy',
              optimizer = optimizer,
              metrics=['accuracy'])
reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.1,
                              patience=3, min_lr=1e-7, verbose=1)
history = model.fit(train_generator,
                    validation_data = test_generator,
                    epochs = 20,
                    shuffle = True,
                    callbacks=[reduce_lr])
model.save('model.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08964338055691255, 'fraction_numerical': 0.02613580850024426, 'mean_word_length': 1.6368319381841596, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 29, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '206398', 'license': 'MIT', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1060, 'n_words': 239, 'path': 'Notebooks/Food_Classification.ipynb', 'repo_name': 'Dstri26/SeTra', 'size': '4094'}