Переменная Conv_featuresbatch_norm / beta / Adam / не существует или не была создана с помощью tf.get_variable (). Вы хотели установить reuse = tf.AUTO_REUSE - PullRequest
0 голосов
/ 18 апреля 2020

Я попытался tf.reset_default_graph (), но все равно ошибка приходит. Я столкнулся с десятками ошибок из релизной версии. Почему в тензорном потоке много ошибок? Если проблема с версией, я надеюсь предоставить информацию о версии тоже. Есть много открытых источников на inte rnet, но они бесполезны из-за ошибок. Я собрал около десяти проектов в inte rnet только до тех пор, пока не обнаружил, что программа работает нормально, но все ошибки в результате. Наконец, при попытке исправить ошибки.

Версии зависимостей:

absl-py                   0.9.0                    pypi_0    pypi
alabaster                 0.7.12                   pypi_0    pypi
astor                     0.8.1                    pypi_0    pypi
astroid                   2.3.3                    pypi_0    pypi
atomicwrites              1.3.0                    pypi_0    pypi
attrs                     19.3.0                   pypi_0    pypi
autopep8                  1.5.1                    pypi_0    pypi
babel                     2.8.0                    pypi_0    pypi
backcall                  0.1.0                    pypi_0    pypi
bcrypt                    3.1.7                    pypi_0    pypi
blas                      1.0                         mkl
bleach                    1.5.0                    pypi_0    pypi
cachetools                4.1.0                    pypi_0    pypi
certifi                   2020.4.5.1       py36h9f0ad1d_0    conda-forge
cffi                      1.14.0           py36h7a1dbc1_0
chardet                   3.0.4                    pypi_0    pypi
cloudpickle               1.3.0                    pypi_0    pypi
colorama                  0.4.3                    pypi_0    pypi
cryptography              2.9                      pypi_0    pypi
cudatoolkit               10.0.130                      0
cycler                    0.10.0                   pypi_0    pypi
decorator                 4.4.2                    pypi_0    pypi
defusedxml                0.6.0                    pypi_0    pypi
diff-match-patch          20181111                 pypi_0    pypi
dill                      0.3.1.1                  pypi_0    pypi
docutils                  0.16                     pypi_0    pypi
entrypoints               0.3                      pypi_0    pypi
enum34                    1.1.10                   pypi_0    pypi
ffmpeg                    1.4                      pypi_0    pypi
flake8                    3.7.9                    pypi_0    pypi
freetype                  2.9.1                ha9979f8_1
gast                      0.2.2                    pypi_0    pypi
google-auth               1.14.0                   pypi_0    pypi
google-auth-oauthlib      0.4.1                    pypi_0    pypi
google-pasta              0.2.0                    pypi_0    pypi
grpcio                    1.28.1                   pypi_0    pypi
h5py                      2.10.0                   pypi_0    pypi
helpdev                   0.6.10                   pypi_0    pypi
hickle                    3.4.6                    pypi_0    pypi
html5lib                  0.9999999                pypi_0    pypi
icc_rt                    2019.0.0             h0cc432a_1
idna                      2.9                      pypi_0    pypi
imageio                   2.8.0                    pypi_0    pypi
imagesize                 1.2.0                    pypi_0    pypi
importlib-metadata        1.6.0                    pypi_0    pypi
intel-openmp              2020.0                      166
intervaltree              3.0.2                    pypi_0    pypi
ipykernel                 5.2.1                    pypi_0    pypi
ipython                   7.13.0                   pypi_0    pypi
ipython-genutils          0.2.0                    pypi_0    pypi
isort                     4.3.21                   pypi_0    pypi
jedi                      0.15.2                   pypi_0    pypi
jinja2                    2.11.2                   pypi_0    pypi
joblib                    0.14.1                   pypi_0    pypi
jpeg                      9b                   hb83a4c4_2
jsonschema                3.2.0                    pypi_0    pypi
jupyter-client            6.1.3                    pypi_0    pypi
jupyter-core              4.6.3                    pypi_0    pypi
keras                     2.3.1                    pypi_0    pypi
keras-applications        1.0.8                    pypi_0    pypi
keras-preprocessing       1.1.0                    pypi_0    pypi
keyring                   21.2.0                   pypi_0    pypi
kiwisolver                1.2.0                    pypi_0    pypi
lazy-object-proxy         1.4.3                    pypi_0    pypi
libgpuarray               0.7.6                hfa6e2cd_0
libpng                    1.6.37               h2a8f88b_0
libpython                 2.1                      py36_0
libtiff                   4.1.0                h56a325e_0
m2w64-binutils            2.25.1                        5
m2w64-bzip2               1.0.6                         6
m2w64-crt-git             5.0.0.4636.2595836               2
m2w64-gcc                 5.3.0                         6
m2w64-gcc-ada             5.3.0                         6
m2w64-gcc-fortran         5.3.0                         6
m2w64-gcc-libgfortran     5.3.0                         6
m2w64-gcc-libs            5.3.0                         7
m2w64-gcc-libs-core       5.3.0                         7
m2w64-gcc-objc            5.3.0                         6
m2w64-gmp                 6.1.0                         2
m2w64-headers-git         5.0.0.4636.c0ad18a               2
m2w64-isl                 0.16.1                        2
m2w64-libiconv            1.14                          6
m2w64-libmangle-git       5.0.0.4509.2e5a9a2               2
m2w64-libwinpthread-git   5.0.0.4634.697f757               2
m2w64-make                4.1.2351.a80a8b8               2
m2w64-mpc                 1.0.3                         3
m2w64-mpfr                3.1.4                         4
m2w64-pkg-config          0.29.1                        2
m2w64-toolchain           5.3.0                         7
m2w64-tools-git           5.0.0.4592.90b8472               2
m2w64-windows-default-manifest 6.4                           3
m2w64-winpthreads-git     5.0.0.4634.697f757               2
m2w64-zlib                1.2.8                        10
mako                      1.1.2                      py_0
markdown                  3.2.1                    pypi_0    pypi
markupsafe                1.1.1            py36he774522_0
matplotlib                3.2.1                    pypi_0    pypi
mccabe                    0.6.1                    pypi_0    pypi
mistune                   0.8.4                    pypi_0    pypi
mkl                       2020.0                      166
mkl-service               2.3.0            py36hb782905_0
mkl_fft                   1.0.15           py36h14836fe_0
mkl_random                1.1.0            py36h675688f_0
msys2-conda-epoch         20160418                      1
nbconvert                 5.6.1                    pypi_0    pypi
nbformat                  5.0.5                    pypi_0    pypi
networkx                  2.4                      pypi_0    pypi
ninja                     1.9.0            py36h74a9793_0
notebook                  6.0.3                    pypi_0    pypi
numpy                     1.18.2                   pypi_0    pypi
numpy-base                1.18.1           py36hc3f5095_1
numpydoc                  0.9.2                    pypi_0    pypi
oauthlib                  3.1.0                    pypi_0    pypi
olefile                   0.46                     py36_0
opencv-python             4.2.0.34                 pypi_0    pypi
opt-einsum                3.2.1                    pypi_0    pypi
packaging                 20.3                     pypi_0    pypi
pandas                    1.0.3                    pypi_0    pypi
pandocfilters             1.4.2                    pypi_0    pypi
paramiko                  2.7.1                    pypi_0    pypi
parso                     0.5.2                    pypi_0    pypi
pathtools                 0.1.2                    pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
pickle5                   0.0.9            py36hfa6e2cd_0    conda-forge
pickleshare               0.7.5                    pypi_0    pypi
pillow                    7.0.0                    pypi_0    pypi
pip                       20.0.2                   py36_1
pluggy                    0.13.1                   pypi_0    pypi
prometheus-client         0.7.1                    pypi_0    pypi
prompt-toolkit            3.0.5                    pypi_0    pypi
protobuf                  3.11.3                   pypi_0    pypi
psutil                    5.7.0                    pypi_0    pypi
ptyprocess                0.6.0                    pypi_0    pypi
pyarrow                   0.16.0                   pypi_0    pypi
pyasn1                    0.4.8                    pypi_0    pypi
pyasn1-modules            0.2.8                    pypi_0    pypi
pycodestyle               2.5.0                    pypi_0    pypi
pycparser                 2.20                       py_0
pydocstyle                5.0.2                    pypi_0    pypi
pyflakes                  2.2.0                    pypi_0    pypi
pygments                  2.6.1                    pypi_0    pypi
pygpu                     0.7.6            py36h452e1ab_0
pylint                    2.4.4                    pypi_0    pypi
pynacl                    1.3.0                    pypi_0    pypi
pyparsing                 2.4.7                    pypi_0    pypi
pyqt5                     5.12.3                   pypi_0    pypi
pyqt5-sip                 12.7.2                   pypi_0    pypi
pyqtwebengine             5.12.1                   pypi_0    pypi
pyrsistent                0.16.0                   pypi_0    pypi
python                    3.6.10               h9f7ef89_1
python-dateutil           2.8.1                    pypi_0    pypi
python-jsonrpc-server     0.3.4                    pypi_0    pypi
python-language-server    0.31.9                   pypi_0    pypi
python_abi                3.6                     1_cp36m    conda-forge
pytorch                   1.2.0           py3.6_cuda100_cudnn7_1    pytorch
pytz                      2019.3                   pypi_0    pypi
pywavelets                1.1.1                    pypi_0    pypi
pywin32                   227                      pypi_0    pypi
pywin32-ctypes            0.2.0                    pypi_0    pypi
pywinpty                  0.5.7                    pypi_0    pypi
pyyaml                    5.3.1                    pypi_0    pypi
pyzmq                     19.0.0                   pypi_0    pypi
qdarkstyle                2.8.1                    pypi_0    pypi
qtawesome                 0.7.1                    pypi_0    pypi
qtconsole                 4.7.3                    pypi_0    pypi
qtpy                      1.9.0                    pypi_0    pypi
requests                  2.23.0                   pypi_0    pypi
requests-oauthlib         1.3.0                    pypi_0    pypi
rope                      0.16.0                   pypi_0    pypi
rsa                       4.0                      pypi_0    pypi
scikit-image              0.16.2                   pypi_0    pypi
scikit-learn              0.22.2.post1             pypi_0    pypi
scipy                     1.1.0                    pypi_0    pypi
send2trash                1.5.0                    pypi_0    pypi
setuptools                46.1.3                   py36_0
six                       1.14.0                   py36_0
snowballstemmer           2.0.0                    pypi_0    pypi
sortedcontainers          2.1.0                    pypi_0    pypi
sphinx                    3.0.1                    pypi_0    pypi
sphinxcontrib-applehelp   1.0.2                    pypi_0    pypi
sphinxcontrib-devhelp     1.0.2                    pypi_0    pypi
sphinxcontrib-htmlhelp    1.0.3                    pypi_0    pypi
sphinxcontrib-jsmath      1.0.1                    pypi_0    pypi
sphinxcontrib-qthelp      1.0.3                    pypi_0    pypi
sphinxcontrib-serializinghtml 1.1.4                    pypi_0    pypi
spyder                    4.1.2                    pypi_0    pypi
spyder-kernels            1.9.0                    pypi_0    pypi
sqlite                    3.31.1               he774522_0
tensorboard               1.15.0                   pypi_0    pypi
tensorflow-estimator      1.15.1                   pypi_0    pypi
tensorflow-gpu            2.0.0                    pypi_0    pypi
tensorflow-gpu-estimator  2.1.0                    pypi_0    pypi
tensorflow-tensorboard    0.4.0                    pypi_0    pypi
termcolor                 1.1.0                    pypi_0    pypi
terminado                 0.8.3                    pypi_0    pypi
testpath                  0.4.4                    pypi_0    pypi
theano                    1.0.4                    py36_0
tk                        8.6.8                hfa6e2cd_0
torchvision               0.4.0                py36_cu100    pytorch
tornado                   6.0.4                    pypi_0    pypi
tqdm                      4.45.0                   pypi_0    pypi
traitlets                 4.3.3                    pypi_0    pypi
typed-ast                 1.4.1                    pypi_0    pypi
urllib3                   1.25.8                   pypi_0    pypi
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.16.27012          hf0eaf9b_1
watchdog                  0.10.2                   pypi_0    pypi
wcwidth                   0.1.9                    pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
werkzeug                  1.0.1                    pypi_0    pypi
wheel                     0.34.2                   py36_0
wincertstore              0.2              py36h7fe50ca_0
wrapt                     1.11.2                   pypi_0    pypi
xz                        5.2.5                h62dcd97_0
yapf                      0.29.0                   pypi_0    pypi
zipp                      3.1.0                    pypi_0    pypi
zlib                      1.2.11               h62dcd97_3
zstd                      1.3.7                h508b16e_0

Код из solver.py, где возникает ошибка:

class CaptioningSolver(object):
    def __init__(self, model, data, **kwargs):
        self.model = model
        self.train_data = data['train_data']
        self.n_epochs = kwargs.pop('n_epochs')
        self.batch_size = kwargs.pop('batch_size')
        self.update_rule = kwargs.pop('update_rule')
        self.learning_rate = kwargs.pop('learning_rate')

        self.print_every = kwargs.pop('print_every')
        self.save_every = kwargs.pop('save_every')

        self.data_path = kwargs.pop('data_path')

        self.log_path = kwargs.pop('log_path')
        self.model_path = kwargs.pop('model_path')
        self.test_result_save_path = kwargs.pop('test_result_save_path')
        self.models_val_disp = kwargs.pop('models_val_disp')

        self.pretrained_model = kwargs.pop('pretrained_model')
        self.test_model = kwargs.pop('test_model')

        # set an optimizer by update rule
        if self.update_rule == 'adam':
            self.optimizer = tf.train.AdamOptimizer
        elif self.update_rule == 'momentum':
            self.optimizer = tf.train.MomentumOptimizer
        elif self.update_rule == 'rmsprop':
            self.optimizer = tf.train.RMSPropOptimizer

        # create necessary folders
        if not os.path.exists(self.model_path):
            os.makedirs(self.model_path)
        if not os.path.exists(self.log_path):
            os.makedirs(self.log_path)
        if not os.path.exists(self.test_result_save_path):
            os.makedirs(self.test_result_save_path)

    def train(self):
        # train dataset
        features = np.array(self.train_data['features'])
        labels = np.array(self.train_data['labels'])
        video_ids = np.array(self.train_data['video_ids'])

        n_iters_per_epoch = int(labels.size / self.batch_size)

        # # mix up the training data
        # rand_idxs = np.random.permutation(len(labels))
        # labels = labels1[rand_idxs]
        # video_ids = video_ids1[rand_idxs]
        # features = features[rand_idxs]

        # build graphs for training model and sampling captions
        loss = self.model.build_model()

        #tf.reset_default_graph()
        tf.get_variable_scope().reuse_variables()  # set the 'reuse' of each variable as True        
        #tf.variable_scope(tf.get_variable_scope(), reuse=True)        
        #tf.variable_scope(tf.get_variable_scope()):


        _, _, sam_labels = self.model.build_sampler()

        # train op
        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)
            tf.scalar_summary('batch_loss', loss)  # add those to the observing process

        # add the variables into observation
        for var in tf.trainable_variables():
            tf.histogram_summary(var.op.name, var)
        for grad, var in grads_and_vars:
            tf.histogram_summary(var.op.name + '/gradient', grad)

        # train_summary = tf.merge_all_summaries()
        print("The number of epoch: %d" % self.n_epochs)
        print("Data size: %d" % (len(labels)))
        print("Batch size: %d" % self.batch_size)
        print("Iterations per epoch: %d" % (n_iters_per_epoch))

        config = tf.ConfigProto(allow_soft_placement=True)
        # config.gpu_options.per_process_gpu_memory_fraction=0.9
        config.gpu_options.allow_growth = True
        with tf.Session(config=config) as sess:
            print('Session created')
            tf.initialize_all_variables().run()
            # train_summary_writer = tf.train.SummaryWriter(self.log_path, graph=tf.get_default_graph())
            saver = tf.train.Saver(max_to_keep=50)

            if self.pretrained_model is not None:
                print("Start training with pretrained Model..")
                saver.restore(sess, self.pretrained_model)

            prev_loss = -1
            curr_loss = 0
            start_t = time.time()

            # training process -- n_epochs iterations + n_iter_per_epoch
            for e in range(self.n_epochs):
                for i in range(n_iters_per_epoch):
                    S = i * self.batch_size
                    E = (i + 1) * self.batch_size
                    labels_batch = labels[S:E]
                    video_ids_batch = video_ids[S:E]
                    features_batch = features[S:E]
                    label_batch_idxs = np.array([[self.model.label_to_idx[per] for per in PER] for PER in labels_batch])

                    feed_dict = {self.model.features: features_batch, self.model.label_idxs: label_batch_idxs}
                    _, l = sess.run([train_op, loss], feed_dict)

                    curr_loss += l

                    # # write summary for tensorboard visualization
                    # if i % 10 == 0:
                    #     summary = sess.run(train_summary, feed_dict)
                    #     train_summary_writer.add_summary(summary, e * n_iters_per_epoch + i)

                    # show the current training condition
                    if (i + 1) % self.print_every == 0:
                        print("\nTrain loss at epoch %d & iteration %d (mini-batch): %.5f" % (e + 1, i + 1, l))
                        sam_labels_list = sess.run(sam_labels, feed_dict)

                        # decode the training result
                        gen_label_idxs, gen_labels = decode(sam_labels_list, self.model.idx_to_label)
                        org_label_idxs = label_batch_idxs[:, 0]

                        # visualize the current comparison
                        for j in range(len(org_label_idxs)):
                            print(video_ids_batch[j])
                            Ground_truth = 'org: ' + str(org_label_idxs[j])
                            Generated_one = 'gen: ' + str(gen_label_idxs[j])
                            print(Ground_truth + '--V.S.--' + Generated_one)
                        print('the current accurancy rate: ' +
                              str(accurate_percentage(gen_label_idxs, org_label_idxs)))

                print("Previous epoch loss: ", prev_loss)
                print("Current epoch loss: ", curr_loss)
                print("Elapsed time: ", time.time() - start_t)
                prev_loss = curr_loss
                curr_loss = 0

                # save model's parameters
                if (e + 1) % self.save_every == 0:
                    saver.save(sess, self.model_path + 'model', global_step=e + 1)
                    print("model-%s saved." % (e + 1))

Полный стек след:

  File "C:\Users\NewServer\Desktop\Action_Recognition_using_Visual_Attention-master\train.py", line 47, in <module>
    solver.train()

  File "C:\Users\NewServer\Desktop\Action_Recognition_using_Visual_Attention-master\core\solver.py", line 84, in train
    train_op = optimizer.apply_gradients(grads_and_vars=grads_and_vars)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\training\optimizer.py", line 597, in apply_gradients
    self._create_slots(var_list)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\training\adam.py", line 131, in _create_slots
    self._zeros_slot(v, "m", self._name)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\training\optimizer.py", line 1156, in _zeros_slot
    new_slot_variable = slot_creator.create_zeros_slot(var, op_name)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\training\slot_creator.py", line 190, in create_zeros_slot
    colocate_with_primary=colocate_with_primary)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\training\slot_creator.py", line 164, in create_slot_with_initializer
    dtype)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\training\slot_creator.py", line 74, in _create_slot_var
    validate_shape=validate_shape)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 1500, in get_variable
    aggregation=aggregation)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 1243, in get_variable
    aggregation=aggregation)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 567, in get_variable
    aggregation=aggregation)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 519, in _true_getter
    aggregation=aggregation)

  File "C:\Users\NewServer\anaconda3\envs\myconda\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 886, in _get_single_variable
    "reuse=tf.AUTO_REUSE in VarScope?" % name)

ValueError: Variable Conv_featuresbatch_norm/beta/Adam/ does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=tf.AUTO_REUSE in VarScope?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...