Giter Club home page Giter Club logo

model-training-tensorflow's Introduction

model-training-tensorflow

Tensorflow model for training the CNN on the Ck+ dataset

model-training-tensorflow's People

Contributors

aaronward avatar

Stargazers

 avatar

Watchers

 avatar  avatar

model-training-tensorflow's Issues

Tensorflow prediction keeps returning a sequence of the same numbers

I feed in a random sample of 10 test data images and most of the time (probably 9 times out of 10) i returns the number sequence of the same number, like [ 2 2 2 2 2 2 2 2 2 2] or [1 1 1 1 1 1 1 1 1 1 1 ]

def test_network(x, images, labels):
    sample_images, sample_labels = random_sample(images, labels)
    sample_images = np.array(sample_images).astype(float)

    pred = convolutional_network(x)
    correct_pred = tf.argmax(pred, 1)

    with tf.Session() as sess: 
        sess.run(tf.global_variables_initializer())
        saver = tf.train.import_meta_graph(TRAINED_MODEL + 'trained_model.ckpt.meta')
        saver.restore(sess, TRAINED_MODEL + 'trained_model.ckpt' )
        print('session restored...')
        
   #Here is where i feed the 10 random images
        predicted = sess.run([correct_pred], feed_dict={x: sample_images})[0]


        print('Correct Labels: ', sample_labels)
        print('Predicted Labels: ', predicted)

        
        #Plot the images samples in a grid with the predicted
        #outputs and the true outputs
        fig = plt.figure(figsize=(10, 10))
        for i in range(len(sample_images)):
            truth = sample_labels[i]
            prediction = predicted[i]
            plt.subplot(5, 2,1+i)
            plt.axis('off')
            color='green' if truth == prediction else 'red'
            plt.text(60, 10, "Correct:        {0}\nPrediction: {1}".format(truth, prediction), 
                     fontsize=12, color=color)
            plt.imshow(sample_images[i], cmap='gray')
        plt.show() 
     
test_network(x, images, labels)

22222222

SOLUTION

it's happening because of correct_pred = tf.argmax(pred, 1), it's giving you 
class with the highest probability after the softmax. You can use predicted
 = sess.run(pred, feed_dict={x: test_images[0:10]}). Now, you will get 
probability of each class for given images For example you might 
get [.1, .05, .05 , .6, .1, .1] for your 6 classes. You won't get [0,0,0,1,0,0].
Now, argmax will give you index corresponding to .6.

Also, add :
pred_ = tf.nn.softmax(pred)
predicted = sess.run(pred_, feed_dict={x: test_images[0:10]})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.