LucasSheng / avatar-net

Avatar-Net: Multi-scale Zero-shot Style Transfer by Feature Decoration
https://lucassheng.github.io/avatar-net/
178 stars 38 forks source link

vgg_19 weight never load? #2

Open ChiFang opened 6 years ago

ChiFang commented 6 years ago

I try to run evaluate_style_transfer.py but fail....

Error msg: style_image_features = losses.extract_image_features(style, self.network_name) in avatar_net.py

ValueError: Variable vgg_19/conv1/conv1_1/weights does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=tf.AUTO_REUSE in VarScope?
We've got an error while stopping in post-mortem: <class 'KeyboardInterrupt'>

I have download "model.ckpt-120000" from your GoogleDrive and vgg_19.ckpt and set "checkpoint_path" in AvatarNet_config.yml to path of vgg_19.ckpt

but you seem never use checkpoint_path in this project...

any suggestion?

LucasSheng commented 6 years ago

The checkpoint_path in AvatarNet_config.yml is used for network training.

You may just use the model.ckpt-120000 for the running of evaluate_style_transfer.py, as variables in VGG-19 has also been saved in this model file.

I would like more log message if you still fail to run the evaluation code.

ChiFang commented 6 years ago

my tensorflow version is 1.4. I find vgg.py comes from here and yours is out of date.

the difference between your vgg19 and tensorflow master is "reuse" argument. After replace vgg.py with tensorflow losses.extract_image_features work fine. but losses.compute_content_features will fail:

Error msg:

instance_label = features.keys()[0] in compute_content_features 

TypeError: 'odict_keys' object does not support indexing

------------------------Update------------------------------ I have successfully run the evaluation code. the root cause are "reuse" argument and instance_label

  1. I need set reuse=False for style_image_features extract_image_features and reuse=True for inputs_image_features
  2. I use hard-code instance_label ("vgg_19") for workaround compute_content_features
JianqiangRen commented 6 years ago

When I want to train, I get the error information as below, and I'm sure about that the checkpoint_path in config is correctly set.

Finish loading the dataset meta data of [MSCOCO]. Finish loading the model [AvatarNet] configuration Traceback (most recent call last): File "train_image_reconstruction.py", line 403, in <module> tf.app.run() File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "train_image_reconstruction.py", line 346, in main total_loss = model.build_train_graph(images) File "/gruntdata/app_data/xueluo/avatar-net/net/avatar_net.py", line 160, in build_train_graph outputs = self.hierarchical_autoencoder(inputs, reuse=False) File "/gruntdata/app_data/xueluo/avatar-net/net/avatar_net.py", line 139, in hierarchical_autoencoder inputs, self.network_name) File "/gruntdata/app_data/xueluo/avatar-net/net/losses.py", line 86, in extract_image_features inputs, spatial_squeeze=False, is_training=False, reuse=reuse) File "/gruntdata/app_data/xueluo/avatar-net/net/vgg.py", line 226, in vgg_19 net = slim.repeat(inputs, 2, slim.conv2d, 64, [3, 3], scope='conv1') File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 2346, in repeat outputs = layer(outputs, *args, **kwargs) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args return func(*args, **current_args) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1033, in convolution outputs = layer.apply(inputs) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 671, in apply return self.__call__(inputs, *args, **kwargs) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 559, in __call__ self.build(input_shapes[0]) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/layers/convolutional.py", line 143, in build dtype=self.dtype) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 458, in add_variable trainable=trainable and self.trainable) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 1203, in get_variable constraint=constraint) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 1092, in get_variable constraint=constraint) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 417, in get_variable return custom_getter(**custom_getter_kwargs) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1539, in layer_variable_getter return _model_variable_getter(getter, *args, **kwargs) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1531, in _model_variable_getter custom_getter=getter, use_resource=use_resource) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args return func(*args, **current_args) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 262, in model_variable use_resource=use_resource) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args return func(*args, **current_args) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 217, in variable use_resource=use_resource) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 394, in _true_getter use_resource=use_resource, constraint=constraint) File "/home/jianqiang.rjq/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 760, in _get_single_variable "reuse=tf.AUTO_REUSE in VarScope?" % name) ValueError: Variable vgg_19/conv1/conv1_1/weights does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=tf.AUTO_REUSE in VarScope? could you tell me how to solve that?

sunshineatnoon commented 6 years ago

@ChiFang Could u give more details on how to run the evaluation code? I changed the vgg.py with up-to-date vgg.py, but still get the reuse error.

ChiFang commented 6 years ago

Hi @sunshineatnoon check following action item:

  1. check vgg19 model path in .yml
  2. make sure keras version is 2.0.8, newest version will crash in losses.py
  3. style_image_features = losses.extract_image_features(style, self.network_name, reuse=False) in avatarnet.py
  4. make instance_label = "vgg_19" in losses.py directly
sunshineatnoon commented 6 years ago

@ChiFang Thanks!

AAnoosheh commented 5 years ago

Why should VGG be even loaded during inference anyway?

fzy139 commented 3 years ago

An alternative way is to download vgg19 manually from vgg19.ckpt and modify the model path in .yml.

SolicTous commented 3 years ago

@ChiFang, Thank you. It works even with TF_1.15 and Keras 2.4.3