Giter Site home page Giter Site logo

Comments (5)

arieling avatar arieling commented on July 18, 2024

did you change the line "self.optimizer = tf.train.AdamOptimizer" in init ?

from show-attend-and-tell.

JaneLou avatar JaneLou commented on July 18, 2024

@arieling No, I didn't. Since the version of my tensorflow is 1.1.0, I only replace some basic functions, now the error is as follows:
work@lab-server03:~/ljz/show-attend-and-tell-master$ python train.py
image_idxs <type 'numpy.ndarray'> (399998,) int32
file_names <type 'numpy.ndarray'> (82783,) <U55
word_to_idx <type 'dict'> 23110
features <type 'numpy.ndarray'> (82783, 196, 512) float32
captions <type 'numpy.ndarray'> (399998, 17) int32
Elapse time: 13.43
image_idxs <type 'numpy.ndarray'> (19589,) int32
file_names <type 'numpy.ndarray'> (4052,) <U51
features <type 'numpy.ndarray'> (4052, 196, 512) float32
captions <type 'numpy.ndarray'> (19589, 17) int32
Elapse time: 0.65
Traceback (most recent call last):
File "train.py", line 25, in
main()
File "train.py", line 22, in main
solver.train()
File "/home/work/ljz/show-attend-and-tell-master/core/solver.py", line 81, in train
_, _, generated_captions = self.model.build_sampler(max_len=20)
File "/home/work/ljz/show-attend-and-tell-master/core/model.py", line 216, in build_sampler
_, (c, h) = lstm_cell(inputs=tf.concat(axis=1, values=[x, context]), state=[c, h])
File "/home/work/.local/lib/python2.7/site-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py", line 235, in call
with _checked_scope(self, scope or "basic_lstm_cell", reuse=self._reuse):
File "/usr/lib/python2.7/contextlib.py", line 17, in enter
return self.gen.next()
File "/home/work/.local/lib/python2.7/site-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.py", line 93, in _checked_scope
"the argument reuse=True." % (scope_name, type(cell).name))
ValueError: Attempt to have a second RNNCell use the weights of a variable scope that already has weights: 'lstm/basic_lstm_cell'; and the cell was not constructed as BasicLSTMCell(..., reuse=True). To share the weights of an RNNCell, simply reuse it in your second calculation, or create a new one with the argument reuse=True.

from show-attend-and-tell.

yunjey avatar yunjey commented on July 18, 2024

@JaneLou You should use TensorFlow 0.11 to run the code in this repo.

from show-attend-and-tell.

jiecaoyu avatar jiecaoyu commented on July 18, 2024

In file core/solver.py, try to change

        tf.get_variable_scope().reuse_variables()
        _, _, generated_captions = self.model.build_sampler(max_len=20)

        with tf.name_scope('optimizer'):
            optimizer = self.optimizer(learning_rate=self.learning_rate)
            grads = tf.gradients(loss, tf.trainable_variables())
            grads_and_vars = list(zip(grads, tf.trainable_variables()))
            train_op = optimizer.apply_gradients(grads_and_vars=grads_and_vars)

to

        with tf.variable_scope(tf.get_variable_scope()) as scope:
            with tf.name_scope('optimizer'):
                tf.get_variable_scope().reuse_variables()
                _, _, generated_captions = self.model.build_sampler(max_len=20)
                optimizer = self.optimizer(learning_rate=self.learning_rate)
                grads = tf.gradients(loss, tf.trainable_variables())
                grads_and_vars = list(zip(grads, tf.trainable_variables()))
        train_op = optimizer.apply_gradients(grads_and_vars=grads_and_vars)

This can help fix the error "ValueError: Variable conv_featuresbatch_norm/beta/Adam/ does not exist". I am testing it with tensorflow 1.0.0

from show-attend-and-tell.

JaneLou avatar JaneLou commented on July 18, 2024

@jiecaoyu Thanks a lot!
I finally refer to the file core/new_solve.py from https://github.com/chychen/caption_generation_with_visual_attention
it works for me!

from show-attend-and-tell.

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.