Coder Social home page Coder Social logo

Comments (3)

supermancc avatar supermancc commented on July 18, 2024

my code here:

    # for loop
    for index in range(720):
            ind=random.randint(0,720)
            img=utils.load_image("./03224jpg/file%d.jpg"%ind)
            img_true_result=[0,1] if ind%2==0 else [1,0]
            batch = img.reshape((1, 224, 224, 3))
            print ind
            prob = sess.run(vgg.prob, feed_dict={images: batch, train_mode: False})
            utils.print_prob(prob[0], './synset.txt') 
            
            # simple 1-step training
            cost = tf.reduce_sum((vgg.prob - true_out) ** 2)
            train = tf.train.GradientDescentOptimizer(0.01).minimize(cost)
            sess.run(train, feed_dict={images: batch, true_out: img_true_result, train_mode: True})
    
            # test classification again, should have a higher probability about tiger
            prob = sess.run(vgg.prob, feed_dict={images: batch, train_mode: False})
            utils.print_prob(prob[0], './synset.txt')

from tensorflow-vgg.

machrisaa avatar machrisaa commented on July 18, 2024

There is a critical error in your code. You should take cost = tf.reduce_sum((vgg.prob - true_out) ** 2) and train = tf.train.GradientDescentOptimizer(0.01).minimize(cost) out of the loop.

Apart from the critical issue, I think you don't need to print the prob 2 times in a loop. You also need to make sure you have correctly modified your VGG, util, and synset.txt to produce 2 classification results instead of 1000.

I think you probably copy the logic in test_vgg19_trainable.py to build your training. Beware that it is just a test runner and NOT a standard code for training a network. I suggest you build one in your case.

If you want to train the model from the initial state, I suggest you read this long discussion here
Usually I would not train the network from scratch. Instead, I will modify the final layers and reuse the pre-trained variables to do a new classification.

from tensorflow-vgg.

supermancc avatar supermancc commented on July 18, 2024

thanks a lot

from tensorflow-vgg.

Related Issues (20)

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.