okeowo1014 commited on
Commit
48ec153
1 Parent(s): 9b6f256

Update train.py

Browse files
Files changed (1) hide show
  1. train.py +10 -5
train.py CHANGED
@@ -3,7 +3,7 @@ import tensorflow as tf
3
  from tensorflow.keras.preprocessing.image import ImageDataGenerator
4
  from tensorflow.keras.applications import VGG16
5
  from tensorflow.keras.layers import Flatten, Dense
6
- from huggingface_hub import push_to_hub_keras
7
 
8
  # Environment variable for Hugging Face token
9
  sac = os.getenv('accesstoken')
@@ -65,7 +65,7 @@ model.compile(loss='binary_crossentropy',
65
  # Train the model
66
  history = model.fit(
67
  train_generator,
68
- epochs=3, # Adjust number of epochs based on dataset size and validation performance
69
  validation_data=validation_generator
70
  )
71
 
@@ -81,10 +81,15 @@ test_loss, test_acc = model.evaluate(test_generator)
81
  print('Test accuracy:', test_acc)
82
 
83
  # Save the model for future use (optional)
84
- model.save('cat_dog_classifier.keras')
 
 
 
 
 
85
  # Upload the model to your Hugging Face space repository
86
- push_to_hub_keras(
87
- model,
88
  repo_id="okeowo1014/catsanddogs",
89
  commit_message="cats and dog image classifier with transfer learning",
90
  tags=["image-classifier", "data-augmentation", "class-weights"],
 
3
  from tensorflow.keras.preprocessing.image import ImageDataGenerator
4
  from tensorflow.keras.applications import VGG16
5
  from tensorflow.keras.layers import Flatten, Dense
6
+ from huggingface_hub import push_to_hub
7
 
8
  # Environment variable for Hugging Face token
9
  sac = os.getenv('accesstoken')
 
65
  # Train the model
66
  history = model.fit(
67
  train_generator,
68
+ epochs=1, # Adjust number of epochs based on dataset size and validation performance
69
  validation_data=validation_generator
70
  )
71
 
 
81
  print('Test accuracy:', test_acc)
82
 
83
  # Save the model for future use (optional)
84
+ # Not recommended for Hugging Face Hub upload (use tf.saved_model.save())
85
+
86
+ # Export the model for Hugging Face Hub using tf.saved_model.save()
87
+ export_dir = 'saved_model' # Create a directory for the SavedModel
88
+ tf.saved_model.save(model, export_dir)
89
+
90
  # Upload the model to your Hugging Face space repository
91
+ push_to_hub(
92
+ model_path=export_dir, # Point to the SavedModel directory
93
  repo_id="okeowo1014/catsanddogs",
94
  commit_message="cats and dog image classifier with transfer learning",
95
  tags=["image-classifier", "data-augmentation", "class-weights"],