text_plain_output_1.png
from tensorflow.keras.preprocessing.image import ImageDataGenerator

import pandas as pd

import zipfile

import zipfile
input_path = '/kaggle/input/dogs-vs-cats'
work_path = '/kaggle/working/data'
train_path = os.path.join(input_path, 'train.zip')
test_path = os.path.join(input_path, 'test1.zip')
with zipfile.ZipFile(train_path, 'r') as zip_ref:
    zip_ref.extractall(work_path)
with zipfile.ZipFile(test_path, 'r') as zip_ref:
    zip_ref.extractall(work_path)

data_dir = work_path
train_dir = data_dir + '/train'
test_dir = data_dir + '/test1'

df = pd.DataFrame()
fnames = os.listdir(train_dir)
class_name = []
for name in fnames:
    class_name.append(name.split('.')[0])
data = {'filename': fnames, 'class': class_name}
df = pd.DataFrame(data)
df = df.sample(frac=1)
train_datagen = ImageDataGenerator(rescale=1 / 255, rotation_range=20, shear_range=0.2, width_shift_range=0.2, height_shift_range=0.2, horizontal_flip=True, zoom_range=0.2)
valid_datagen = ImageDataGenerator(rescale=1 / 255)
idx = int(0.8 * len(df))
train_df = df.iloc[:idx]
valid_df = df.iloc[idx:]
target = (224, 224)
train_set = train_datagen.flow_from_dataframe(train_df, directory=train_dir, shuffle=True, target_size=target, batch_size=64, class_mode='binary')
valid_set = valid_datagen.flow_from_dataframe(valid_df, directory=train_dir, shuffle=False, target_size=target, batch_size=32, class_mode='binary')