Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training loss #3

Open
VincentChong123 opened this issue Jun 9, 2019 · 2 comments
Open

Training loss #3

VincentChong123 opened this issue Jun 9, 2019 · 2 comments

Comments

@VincentChong123
Copy link

VincentChong123 commented Jun 9, 2019

Hi @frotms , @mttbx, @MenSanYan,

Based on your mobilenet_v3.py, I added training code below but I cannot reduce training loss from 6.9.

Do you have sample training code and its training loss? Or do you see any errors in my training code?

Thanks.
tf_mobilenetv3.zip

if __name__ == "__main__":
print("begin ...")
input_test = tf.zeros([2, 224, 224, 3])
num_classes = 1000

if 0:
    model, end_points = mobilenet_v3_small(input_test, num_classes, multiplier=1.0, is_training=True, reuse=None)
else:
    t_steps = 1000
    t_batch = 128
    tf.random.set_random_seed(1)
    input_rand = tf.random.uniform(shape=(t_batch, 224, 224, 3), minval=0, maxval=1)
    x_batch = input_rand
    y_batch = tf.random.uniform(shape=(t_batch,), minval=0, maxval=1000, dtype=tf.int32)

    logits, end_points = mobilenet_v3_small(x_batch, num_classes, multiplier=1.0, is_training=True, reuse=None)

    loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=y_batch))
    #train_ops = tf.train.AdamOptimizer(learning_rate=0.0001).minimize(loss)
    train_ops = tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(loss)

    sess = tf.Session()
    sess.run(tf.global_variables_initializer())
    for s in range(t_steps):
        _, loss_batch = sess.run([train_ops, loss])

        print("steps {:05d} loss {:03f}".format(s, loss_batch))


print("done !")

steps 00000 loss 6.914634
steps 00001 loss 6.907555
steps 00002 loss 6.905149
steps 00003 loss 6.905774
steps 00004 loss 6.904990
@frotms
Copy link
Owner

frotms commented Jun 9, 2019

You lost parameters of batch normalization layer. @weishengchong

with tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)):
    train_ops = optimizer.minimize(loss)

@VincentChong123
Copy link
Author

Hi @frotms ,
Thanks for your advise, it works.

I also use correction below to input constant random number rather than tf.random.uniform that always updates its value during training.

        x_batch  = tf.constant(np.random.uniform(low=0, high=1.0, size=(t_batch, 224, 224,3)).astype(np.float32))
        y_batch = tf.constant(np.random.uniform(size=(t_batch,), low=0, high=num_classes).astype(np.int32))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants