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

Why do I always encounter the error: 'ValueError: Imaginary component 89928690.58258057' #31

Open
BlackAngel-511 opened this issue Apr 12, 2020 · 15 comments

Comments

@BlackAngel-511
Copy link

I use the fid.py to measure fid score of my images datasets, I generated 10000 images in tImages directory and used the command 'python fid.py ./tImages fid_stats_celeba.npz' or 'python fid.py ./tImages ./sImages ' (sImages directory is another images datasets), but waiting a while, I always get a ValueError. e.g. 'ValueError: Imaginary component 89928690.58258057' or
'ValueError: Imaginary component 1.376687186290827e+24'. I don't know which step I did wrong. Could anyone tell me what the problem is, thanks!

error information:
Traceback (most recent call last):
File "fid.py", line 334, in
fid_value = calculate_fid_given_paths(args.path, args.inception, low_profile=args.lowprofile)
File "fid.py", line 317, in calculate_fid_given_paths
fid_value = calculate_frechet_distance(m1, s1, m2, s2)
File "fid.py", line 155, in calculate_frechet_distance
raise ValueError("Imaginary component {}".format(m))
ValueError: Imaginary component 1.376687186290827e+24

@mmderakhshani
Copy link

@BlackAngel-511. I received the same error. Were you able to solve this error? My command was:

python fid.py ../stage2/ ../fid_stats_celeba.npz --gpu 0

@mhex
Copy link
Collaborator

mhex commented Apr 21, 2020

Could you pls post the min/max/mean values of both sigma1 and sigma2?

@mohammadhosseinashoori
Copy link

mohammadhosseinashoori commented Apr 21, 2020

i have a same problem
my command:
!python '/content/fid.py' '/content/real_images_all/img' '/content/generated_images_all/img'

number of images: 8189 (same for real and generated directory)

Traceback (most recent call last):
File "/content/fid.py", line 325, in
fid_value = calculate_fid_given_paths(args.path, args.inception, low_profile=args.lowprofile)
File "/content/fid.py", line 308, in calculate_fid_given_paths
fid_value = calculate_frechet_distance(m1, s1, m2, s2)
File "/content/fid.py", line 148, in calculate_frechet_distance
raise ValueError("Imaginary component {}".format(m))
ValueError: Imaginary component 6.921868576484653e+25

how to solve it?
thank you in advance

@BlackAngel-511
Copy link
Author

I guess that the problem was caused by system environment. When I recreate a new evironment in anconda, the problem magically disappeared.

@mohammadhosseinashoori
Copy link

@BlackAngel-511
thank you for your comment
what is you tensorflow version?

thank you very much

@BlackAngel-511
Copy link
Author

I trid to execute in tensorflow 1.11 or 1.14 and it worked

@mohammadhosseinashoori
Copy link

thank you i will try it

@mohammadhosseinashoori
Copy link

i create a new anaconda environment and install tensorflow version 1.14
it solved my problem
thank you

@mmderakhshani
Copy link

i create a new anaconda environment and install tensorflow version 1.14
it solved my problem
thank you

Shall I ask your python version?

@mohammadhosseinashoori
Copy link

python 3.7.6

@mmderakhshani
Copy link

python 3.7.6

I installed python=3.7.6 and tensorflow-gpu=1.14.0. But I received the same error. Could you please export your environment into .yml file and share it with me?

@mohammadhosseinashoori
Copy link

hello
i installed tensorflow 1.14.0 cpu not gpu, may be it is important ...
link of yml file:
environment_tf_14.zip

@ZejianLi
Copy link
Contributor

Hello, I have the same error.The problem may not comes from the version of Tensorflow. It is from the code.

In https://github.com/bioinf-jku/TTUR/blob/master/fid.py#L88, n_batches = n_images//batch_size means the last batch is dropped, but in the next line pred_arr = np.empty((n_images,2048)) keeps the places for the dropped samples and initializes them with arbitrary values. This seriously influences the final means and stds and causes the numerical error.

It is even worse when the np.empty() gives zeros. In this case there wouldn't be any error but the final fid value would be slightly lower than the real one.

To fix this, we may rewrite pred_arr = np.empty((n_batches*batch_size,2048)).

@3288103265
Copy link
Contributor

The same question and I cannot fix it with creating new environments.

@mhex
Copy link
Collaborator

mhex commented Sep 18, 2020

should be fixed with last commit please test

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

6 participants