Search code examples
tensorflowresnet

Training Resnet-50 with CIFAR-100 dataset in TensorFlow, can't get good accuracy


I am trying to a resnet-50 model in tensorflow by cifar-100 dataset.I have used builtin resnet_v1_50 to create model in tensorflow with two fully connected layer on it's head.But my validation accuracy stuck at nearly 37%.What is the problem???am I configure wrongly define and configure resnet_v1_50??? my model creation code is given below.

import tensorflow as tf
from tensorflow.contrib.slim.python.slim.nets import resnet_v1


X = tf.placeholder(dtype=tf.float32, shape=[None, 32, 32, 3])

Y = tf.placeholder(dtype=tf.float32, shape=[None, 100])


net, end_points = resnet_v1.resnet_v1_50(X,global_pool=False,is_training=True)

flattened = tf.contrib.layers.flatten(net)

dense_fc1 = tf.layers.dense(inputs=flattened,units=625, activation=tf.nn.relu,kernel_initializer=tf.contrib.layers.xavier_initializer())

dropout_fc1 = tf.layers.dropout(inputs=dense_fc1,rate=0.5, training=self.training)

logits = tf.layers.dense(inputs=dropout_fc1, units=num_classes,kernel_initializer = tf.contrib.layers.xavier_initializer())

cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=Y))

optimizer = tf.train.AdamOptimizer(learning_rate=0.001).minimize(cost)

Solution

  • I think you have an extra dense layer. ResNet uses single fully-connected layer with softmax and size=num_classes.

    You might also need to make sure that your hyperparameters are set correctly, like learning_rate and weight_decay and your input processing pipeline is also correct.

    Here is an extra link to see if your pipeline is similar to a working solution.