<jupyter_start><jupyter_text><jupyter_code>#using keras with tensorflow as backend
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
from keras.models import Sequential
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Flatten())
classifier.add(Dense(units = 128, activation = 'relu'))

classifier.add(Dense(units = 1, activation = 'sigmoid'))
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

!pip install PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# Authenticate and create the PyDrive client.
# This only needs to be done once in a notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
fileId = drive.CreateFile({'id': '1AA9ImeJvTWQl_abFo3xr9g62lh7GuMCR'}) #DRIVE_FILE_ID is file id example: 1iytA1n2z4go3uVCwE_vIKouTKyIDjEq
print( fileId['title'])  # folder_data.zip
fileId.GetContentFile('image_class.zip')  # Save Drive file as a local file
!unzip image_class.zip -d ./

from keras.preprocessing.image import ImageDataGenerator
#  from google.colab import drive
#  drive.mount("/content/drive/My Drive/image_class/")
#  !ls "/content/drive/My Drive/image_class/"
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('image_class/train',
target_size = (64, 64),
batch_size = 32,
class_mode = 'binary')
test_set = test_datagen.flow_from_directory('image_class/test',
target_size = (64, 64),
batch_size = 32,
class_mode = 'binary')

classifier.fit_generator(training_set,
steps_per_epoch = 800,
epochs = 25,
validation_data = test_set,
validation_steps = 200)
import numpy as np
from keras.preprocessing import image
test_image = image.load_img('image_class/valid/dog/594.jpeg', target_size = (64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = classifier.predict(test_image)
training_set.class_indices
if result[0][0] == 1:
    prediction = 'dog'
else:
   prediction = 'cat'
print(prediction)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11221647433346597, 'fraction_numerical': 0.029844807003581376, 'mean_word_length': 6.526946107784431, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '307346', 'license': 'MIT', 'n_tokens_mistral': 923, 'n_tokens_neox': 865, 'n_words': 203, 'path': 'imageclassification/image_classification.ipynb', 'repo_name': 'keshab97/100-days-of-ml', 'size': '2513'}