mnicnc404/CartoonGan-tensorflow

Issue with the load_model function of the cortoogan folder

Angkirat opened this issue · 3 comments

I am facing issue while executing the code as below:

could you please help resolve this

2020-02-06 15:50:58.660293: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Using TensorFlow backend.
2020-02-06 15:51:10.433049: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-02-06 15:51:10.433434: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303)
2020-02-06 15:51:10.447289: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DDC2-D-6SGR9B2
2020-02-06 15:51:10.448351: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DDC2-D-6SGR9B2
2020-02-06 15:51:10.448868: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
  File "~/OneDrive/PythonCode/AIR_Open_funEvents/cartoonization/cartoongan.py", line 149, in <module>
    g = load_model("hayao")
  File "~/OneDrive/PythonCode/AIR_Open_funEvents/cartoonization/cartoongan.py", line 82, in load_model
    y = instance_norm_layer(style, "in01_1")(y)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\keras\backend\tensorflow_backend.py", line 75, in symbolic_fn_wrapper
    return func(*args, **kwargs)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\keras\engine\base_layer.py", line 463, in __call__
    self.build(unpack_singleton(input_shapes))
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\keras_contrib-2.0.8-py3.6.egg\keras_contrib\layers\normalization\instancenormalization.py", line 95, in build
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\keras\engine\base_layer.py", line 282, in add_weight
    constraint=constraint)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\keras\backend\tensorflow_backend.py", line 620, in variable
    value, dtype=dtype, name=name, constraint=constraint)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\tensorflow_core\python\keras\backend.py", line 814, in variable
    constraint=constraint)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\tensorflow_core\python\ops\variables.py", line 260, in __call__
    return cls._variable_v2_call(*args, **kwargs)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\tensorflow_core\python\ops\variables.py", line 254, in _variable_v2_call
    shape=shape)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\tensorflow_core\python\ops\variables.py", line 235, in <lambda>
    previous_getter = lambda **kws: default_variable_creator_v2(None, **kws)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\tensorflow_core\python\ops\variable_scope.py", line 2645, in default_variable_creator_v2
    shape=shape)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\tensorflow_core\python\ops\variables.py", line 262, in __call__
    return super(VariableMetaclass, cls).__call__(*args, **kwargs)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 1411, in __init__
    distribute_strategy=distribute_strategy)
  File "~\AppData\Local\Continuum\anaconda3\envs\MyEnv\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 1494, in _init_from_args
    raise ValueError("Tensor-typed variable initializers must either be "
ValueError: Tensor-typed variable initializers must either be wrapped in an init_scope or callable (e.g., `tf.Variable(lambda : tf.truncated_normal([10, 40]))`) when building functions. Please file a feature request if this restriction inconveniences you.```

Hi! Did you manage to find the solution for this problem?

@Angkirat Solved!
step1. I installed tf version 1.14.
step2. In style_transfer/cartoongan/cartoongan.py replace all tf.keras by keras - do not forget to import keras itself there.
step3. In cartoonize.py import tensorflow as tf and under that import line insert tf.enable_eager_execution()
step4. In cartoonize.py find the line transformed_image = model(input_image) and replace it with transformed_image = model(tf.convert_to_tensor(input_image))
Hope now it should be fine.

Thank you @mumtozvalijonov !!
Closing this issue thread.