Commit 27e73aec authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

cast labels to required format

parent b9cc5a9a
...@@ -44,22 +44,22 @@ patch = Sequential([ ...@@ -44,22 +44,22 @@ patch = Sequential([
Activation('relu'), Activation('relu'),
MaxPool2D(padding='same'), MaxPool2D(padding='same'),
Conv2D(100, (3, 3), padding='same', use_bias=False, input_shape=(96,96,3)), Conv2D(100, (3, 3), padding='same', use_bias=False),
BatchNormalization(scale=False), BatchNormalization(scale=False),
Activation('relu'), Activation('relu'),
MaxPool2D(padding='same'), MaxPool2D(padding='same'),
Conv2D(150, (3, 3), padding='same', use_bias=False, input_shape=(96,96,3)), Conv2D(150, (3, 3), padding='same', use_bias=False),
BatchNormalization(scale=False), BatchNormalization(scale=False),
Activation('relu'), Activation('relu'),
MaxPool2D(pool_size=3, strides=2, padding='same'), MaxPool2D(pool_size=3, strides=2, padding='same'),
Conv2D(200, (3, 3), padding='same', use_bias=False, input_shape=(96,96,3)), Conv2D(200, (3, 3), padding='same', use_bias=False),
BatchNormalization(scale=False), BatchNormalization(scale=False),
Activation('relu'), Activation('relu'),
MaxPool2D(padding='same'), MaxPool2D(padding='same'),
Conv2D(250, (3, 3), padding='same', use_bias=False, input_shape=(96,96,3)), Conv2D(250, (3, 3), padding='same', use_bias=False),
BatchNormalization(scale=False), BatchNormalization(scale=False),
Activation('relu'), Activation('relu'),
MaxPool2D(padding='same'), MaxPool2D(padding='same'),
...@@ -388,6 +388,7 @@ def model_fn(features, labels, mode, params=None, config=None): ...@@ -388,6 +388,7 @@ def model_fn(features, labels, mode, params=None, config=None):
return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions) return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)
# Calculate Loss (for both TRAIN and EVAL modes) # Calculate Loss (for both TRAIN and EVAL modes)
labels = tf.cast(labels, dtype="int32")
loss = tf.losses.sparse_softmax_cross_entropy(logits=logits, labels=labels) loss = tf.losses.sparse_softmax_cross_entropy(logits=logits, labels=labels)
# Add the regularization terms to the loss # Add the regularization terms to the loss
if regularization_rate: if regularization_rate:
......
...@@ -401,6 +401,9 @@ def model_fn(features, labels, mode, params=None, config=None): ...@@ -401,6 +401,9 @@ def model_fn(features, labels, mode, params=None, config=None):
if mode == tf.estimator.ModeKeys.PREDICT: if mode == tf.estimator.ModeKeys.PREDICT:
return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions) return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)
# convert labels to the expected int32 format
labels = tf.cast(labels, dtype="int32")
accuracy = tf.metrics.accuracy( accuracy = tf.metrics.accuracy(
labels=labels, predictions=predictions["classes"]) labels=labels, predictions=predictions["classes"])
metrics = {'accuracy': accuracy} metrics = {'accuracy': accuracy}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment