okeowo1014 commited on
Commit
ff8836b
·
1 Parent(s): 1b0b78e

Update trainer.py

Browse files
Files changed (1) hide show
  1. trainer.py +25 -17
trainer.py CHANGED
@@ -9,7 +9,8 @@ import matplotlib.pyplot as plt
9
  import cv2
10
  import tensorflow as tf
11
  from tqdm import tqdm
12
- sac=os.getenv('accesstoken')
 
13
  sn.set(font_scale=1.4)
14
 
15
  class_names = ['buildings', 'forest', 'glacier', 'mountain', 'sea', 'street']
@@ -52,41 +53,48 @@ def load_data():
52
  train_images, train_labels = shuffle(train_images, train_labels, random_state=25)
53
  print("Train: ", train_images.shape, train_labels.shape)
54
  print("Test: ", test_images.shape, test_labels.shape)
55
-
56
- model = tf.keras.models.Sequential([
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)),
58
  tf.keras.layers.MaxPooling2D(2, 2),
59
- tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
60
- tf.keras.layers.MaxPooling2D(2, 2),
61
- tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
62
- tf.keras.layers.MaxPooling2D(2, 2),
63
- tf.keras.layers.Conv2D(128, (3, 3), activation='relu'),
64
  tf.keras.layers.MaxPooling2D(2, 2),
65
  tf.keras.layers.Flatten(),
66
- tf.keras.layers.Dense(512, activation='relu'),
67
- tf.keras.layers.Dense(6, activation='softmax')
68
  ])
69
 
70
  model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
71
- model.fit(train_images, train_labels, epochs=10, validation_split=0.1)
72
 
73
  # Evaluate the model
74
  model.evaluate(test_images, test_labels)
75
 
76
  # save the model
77
  model.save("model.keras")
78
- #from transformers import push_to_hub_keras
79
 
80
  # Save the model
81
- #model.save("model.keras")
82
 
83
  # Upload the model to your Hugging Face space repository
84
  push_to_hub_keras(
85
  model,
86
- repo_id="okeowo1014/imgclassifiertrainingsample",
87
  commit_message="Optional commit message",
88
  tags=["image-classifier", "some_other_tag"],
89
- include_optimizer=True,token=sac
90
  )
91
-
92
-
 
9
  import cv2
10
  import tensorflow as tf
11
  from tqdm import tqdm
12
+
13
+ sac = os.getenv('accesstoken')
14
  sn.set(font_scale=1.4)
15
 
16
  class_names = ['buildings', 'forest', 'glacier', 'mountain', 'sea', 'street']
 
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)
85
 
86
  # save the model
87
  model.save("model.keras")
88
+ # from transformers import push_to_hub_keras
89
 
90
  # Save the model
91
+ # model.save("model.keras")
92
 
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
100
  )