Downloads · 30 days
0
Iqbaliswinning/CATDOGskillacad
CATDOGskillacad is a machine learning model from Iqbaliswinning. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Downloads · 30 days
0
Access
Public
Updated Jun 29, 2024
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md2.1 KB · 58%
From the Hugging Face model README
!pip install tensorflow
import tensorflow as tf from tensorflow.keras.preprocessing.image import ImageDataGenerator import os
train_dir = '/content/dataset'
train_datagen = ImageDataGenerator( rescale=1./255, # Rescale pixel values to [0, 1] shear_range=0.2, # Shear transformation zoom_range=0.2, # Random zoom horizontal_flip=True # Random horizontal flip )
train_generator = train_datagen.flow_from_directory( train_dir, classes=['cats_set', 'dogs_set'], target_size=(224, 224), # Resize images to 224x224 (required input size for many pretrained models) batch_size=32, class_mode='binary' # Since we have two classes (cats and dogs) )
print(f"Found {train_generator.samples} images belonging to {train_generator.num_classes} classes.")
base_model = tf.keras.applications.MobileNetV2(input_shape=(224, 224, 3), include_top=False, weights='imagenet')
base_model.trainable = False
model = tf.keras.Sequential([ base_model, tf.keras.layers.GlobalAveragePooling2D(), tf.keras.layers.Dense(1, activation='sigmoid') # Binary classification (cats vs dogs) ])
model.compile(optimizer=tf.keras.optimizers.Adam(), loss='binary_crossentropy', metrics=['accuracy'])
steps_per_epoch = train_generator.samples // train_generator.batch_size
history = model.fit(train_generator, epochs=10, # Increase epochs as needed steps_per_epoch=steps_per_epoch, verbose=1)
train_loss, train_accuracy = model.evaluate(train_generator) print(f"Training Accuracy: {train_accuracy}")