okeowo1014 commited on
Commit
b326687
·
1 Parent(s): 61a535d

Update trainer.py

Browse files
Files changed (1) hide show
  1. trainer.py +21 -21
trainer.py CHANGED
@@ -13,7 +13,7 @@ from tqdm import tqdm
13
  sac = os.getenv('accesstoken')
14
  sn.set(font_scale=1.4)
15
 
16
- class_names = ['buildings', 'forest', 'glacier', 'mountain', 'sea', 'street']
17
  class_names_label = {class_name: i for i, class_name in enumerate(class_names)}
18
  nb_classes = len(class_names)
19
  print(class_names_label)
@@ -53,32 +53,32 @@ def load_data():
53
  train_images, train_labels = shuffle(train_images, train_labels, random_state=25)
54
  print("Train: ", train_images.shape, train_labels.shape)
55
  print("Test: ", test_images.shape, test_labels.shape)
56
- #
57
- # model = tf.keras.models.Sequential([
58
- # tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)),
59
- # tf.keras.layers.MaxPooling2D(2, 2),
60
- # tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
61
- # tf.keras.layers.MaxPooling2D(2, 2),
62
- # tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
63
- # tf.keras.layers.MaxPooling2D(2, 2),
64
- # tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
65
- # tf.keras.layers.MaxPooling2D(2, 2),
66
- # tf.keras.layers.Flatten(),
67
- # tf.keras.layers.Dense(512, activation='relu'),
68
- # tf.keras.layers.Dense(6, activation='softmax')
69
- # ])
70
- model = tf.keras.Sequential([
71
  tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)),
72
  tf.keras.layers.MaxPooling2D(2, 2),
73
- tf.keras.layers.Conv2D(32, (3, 3), activation='relu'),
 
 
 
 
74
  tf.keras.layers.MaxPooling2D(2, 2),
75
  tf.keras.layers.Flatten(),
76
- tf.keras.layers.Dense(128, activation=tf.nn.relu),
77
- tf.keras.layers.Dense(6, activation=tf.nn.softmax)
78
  ])
 
 
 
 
 
 
 
 
 
79
 
80
  model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
81
- model.fit(train_images, train_labels, epochs=6, validation_split=0.2)
82
 
83
  # Evaluate the model
84
  model.evaluate(test_images, test_labels)
@@ -93,7 +93,7 @@ model.save("model.keras")
93
  # Upload the model to your Hugging Face space repository
94
  push_to_hub_keras(
95
  model,
96
- repo_id="okeowo1014/imgclassifiertraining",
97
  commit_message="Optional commit message",
98
  tags=["image-classifier", "some_other_tag"],
99
  include_optimizer=True, token=sac
 
13
  sac = os.getenv('accesstoken')
14
  sn.set(font_scale=1.4)
15
 
16
+ class_names = ['buildings', 'forest', 'glacier']
17
  class_names_label = {class_name: i for i, class_name in enumerate(class_names)}
18
  nb_classes = len(class_names)
19
  print(class_names_label)
 
53
  train_images, train_labels = shuffle(train_images, train_labels, random_state=25)
54
  print("Train: ", train_images.shape, train_labels.shape)
55
  print("Test: ", test_images.shape, test_labels.shape)
56
+
57
+ model = tf.keras.models.Sequential([
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)),
59
  tf.keras.layers.MaxPooling2D(2, 2),
60
+ tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
61
+ tf.keras.layers.MaxPooling2D(2, 2),
62
+ tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
63
+ tf.keras.layers.MaxPooling2D(2, 2),
64
+ tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
65
  tf.keras.layers.MaxPooling2D(2, 2),
66
  tf.keras.layers.Flatten(),
67
+ tf.keras.layers.Dense(512, activation='relu'),
68
+ tf.keras.layers.Dense(6, activation='softmax')
69
  ])
70
+ # model = tf.keras.Sequential([
71
+ # tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)),
72
+ # tf.keras.layers.MaxPooling2D(2, 2),
73
+ # tf.keras.layers.Conv2D(32, (3, 3), activation='relu'),
74
+ # tf.keras.layers.MaxPooling2D(2, 2),
75
+ # tf.keras.layers.Flatten(),
76
+ # tf.keras.layers.Dense(128, activation=tf.nn.relu),
77
+ # tf.keras.layers.Dense(6, activation=tf.nn.softmax)
78
+ # ])
79
 
80
  model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
81
+ model.fit(train_images, train_labels, epochs=10, validation_split=0.2)
82
 
83
  # Evaluate the model
84
  model.evaluate(test_images, test_labels)
 
93
  # Upload the model to your Hugging Face space repository
94
  push_to_hub_keras(
95
  model,
96
+ repo_id="okeowo1014/imgclassifiera",
97
  commit_message="Optional commit message",
98
  tags=["image-classifier", "some_other_tag"],
99
  include_optimizer=True, token=sac