Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running example code #2

Open
jcasey30 opened this issue Jun 29, 2021 · 3 comments
Open

Error when running example code #2

jcasey30 opened this issue Jun 29, 2021 · 3 comments

Comments

@jcasey30
Copy link

I have been trying to get this repo to work but I am running into an issue. After cloning this repo and downloading the afhq dataset, I attemp to run the code using this command:

python main.py train --dataset_name afhq --dataset_path C:\Users\user\Documents\ATR\data\afhq --batch_size 4 --res 512 --config e --impl ref

Once training starts, however, I get an error returned:

`
Traceback (most recent call last):
File "main.py", line 99, in
main()
File "main.py", line 66, in main
trainer.train()
File "C:\Users\user\Documents\GitHub\StyleGAN2\train.py", line 150, in train
G_loss, D_loss = self.train_step(real_images, real_labels)
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\eager\def_function.py", line 780, in call
result = self._call(*args, **kwds)
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\eager\def_function.py", line 823, in _call
self._initialize(args, kwds, add_initializers_to=initializers)
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\eager\def_function.py", line 696, in _initialize
self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\eager\function.py", line 2855, in _get_concrete_function_internal_garbage_collected
graph_function, _, _ = self._maybe_define_function(args, kwargs)
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\eager\function.py", line 3213, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\eager\function.py", line 3065, in _create_graph_function
func_graph_module.func_graph_from_py_func(
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\framework\func_graph.py", line 986, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\eager\def_function.py", line 600, in wrapped_fn
return weak_wrapped_fn().wrapped(*args, **kwds)
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\eager\function.py", line 3735, in bound_method_wrapper
return wrapped_fn(*args, **kwargs)
File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\framework\func_graph.py", line 973, in wrapper
raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:

C:\Users\user\Documents\GitHub\StyleGAN2\train.py:209 train_step  *
    G_loss, G_reg = self.loss_func.get_G_loss(real_images, real_labels, compute_reg=True)
C:\Users\user\Documents\GitHub\StyleGAN2\modules\losses.py:71 get_G_loss  *
    pl_lengths = tf.math.sqrt(tf.reduce_mean(tf.reduce_sum(tf.square(pl_grads), axis=2), axis=1))
C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\ops\gen_math_ops.py:10321 square  **
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
C:\Users\user\AppData\Local\Continuum\anaconda3\envs\capsule\lib\site-packages\tensorflow\python\framework\op_def_library.py:486 _apply_op_helper
    raise ValueError(

ValueError: Tried to convert 'x' to a tensor and failed. Error: None values not supported.

`

@ammar-deep
Copy link

While I am unsure of the exact cause of your error, I will recommend that you ensure that your model's training images are properly loaded. I just cloned this repository and began training it on my custom dataset using all default settings except the --impl=cuda option, and everything appears to be working fine.

@ammar-deep
Copy link

So the error you mentioned is coming due to the loss ns_pathreg_r1() used for afhq and ffhq. Change the loss to ns_DiffAugment_r1() which doesn't need labels and it will work fine. Due to some unknown reason the number of labels are none when the model starts training while using the ns_pathreg_r1() loss.

@seymayucer
Copy link

seymayucer commented Nov 25, 2022

I have tried many things to use GradientTape.gradient() but could not do it, I switch it to tf.gradients to use StyleGan2 ppl loss, it worked;

#from
       pl_grads = pl_tape.gradient(pl_noise_applied, pl_w)
#to
       pl_grads = tf.gradients(
           ys=pl_noise_applied,
           xs=pl_w
       )[0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants