LynnHo / AttGAN-Tensorflow

AttGAN: Facial Attribute Editing by Only Changing What You Want (IEEE TIP 2019)
MIT License
603 stars 133 forks source link

TypeError #26

Closed shbnm21 closed 4 years ago

shbnm21 commented 4 years ago

hello I have downloaded trained model and trying to test it but i am getting following error. can u please suggest what went wrong?

I am testing it on google colab and using only 182000 to 182637 images. TypeError: Input 'filename' of 'ReadFile' Op has type float32 that does not match expected type of string.

LynnHo commented 4 years ago

@shbnm21 I remember you have solved this issue before? #23

shbnm21 commented 4 years ago

Yes I solved it when I was training it

But in testing it's not working.

I had used dataset folder where I kept data folder

And that solved my problem but same thing not working with testing.

LynnHo commented 4 years ago

@shbnm21 I am sorry for the late response. Did you solve the problem? I cannot find out the problem from your information, did you totally follow the instruction in README? And one thing to be checked: Keep all the data including training set and testing set.

shbnm21 commented 4 years ago

No ,I have not solved it.

I tried previous solution but its not working.Problem is in data.py

Traceback (most recent call last): File "data.py", line 260, in data = Celeba('/content/gdrive/My Drive/Colab Notebooks/AttGAN-Tensorflow/dataset/data', atts, 128, 32, part='val') File "data.py", line 222, in init repeat=repeat) File "data.py", line 66, in disk_image_batch_dataset mapfunc, num_threads, shuffle, buffer_size, repeat) File "data.py", line 19, in batch_dataset dataset = dataset.map(map_func, num_parallel_calls=num_threads) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 1913, in map self, map_func, num_parallel_calls, preserve_cardinality=False)) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 3472, in init use_legacy_function=use_legacy_function) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 2713, in init self._function = wrapper_fn._get_concrete_function_internal() File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 1853, in _get_concrete_function_internal *args, *kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 1847, in _get_concrete_function_internal_garbage_collected graphfunction, , _ = self._maybe_define_function(args, kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 2147, in _maybe_define_function graph_function = self._create_graph_function(args, kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 2038, in _create_graph_function capture_by_value=self._capture_by_value), File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/func_graph.py", line 915, in func_graph_from_py_func func_outputs = python_func(func_args, *func_kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 2707, in wrapper_fn ret = _wrapper_helper(args) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/data/ops/dataset_ops.py", line 2652, in _wrapper_helper ret = autograph.tf_convert(func, ag_ctx)(*nested_args) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/autograph/impl/api.py", line 237, in wrapper raise e.ag_error_metadata.to_exception(e) TypeError: in converted code:

data.py:59 map_func_  *
    return map_func(*parse_func(*args))
data.py:52 parse_func  *
    img = tf.io.read_file(path)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/gen_io_ops.py:626 read_file
    "ReadFile", filename=filename, name=name)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/op_def_library.py:551 _apply_op_helper
    (prefix, dtypes.as_dtype(input_arg.type).name))

TypeError: Input 'filename' of 'ReadFile' Op has type float32 that does not match expected type of string.

Problem is in the datapath

I am not understanding what am i doing wrong

On google colab I am giving following path '/content/gdrive/My Drive/Colab Notebooks/AttGAN-Tensorflow/dataset/data'

i also changed it to '/content/gdrive/My Drive/Colab Notebooks/AttGAN-Tensorflow/data'

then also getting same error

LynnHo commented 4 years ago

@shbnm21 I cannot figure out your problem, have you totally followed the README.md, or you have made some modification?

shbnm21 commented 4 years ago

Yes I followed readme. I have a question. Do I need to use all the images Cz for testing I have uploaded only 637 images and according to it used attribute file.

shbnm21 commented 4 years ago

I will test the code on Windows ,anaconda and then let u know.

LynnHo commented 4 years ago

@shbnm21 You can upload all data for safety. Besides, what do you mean below?

I am giving following path
'/content/gdrive/My Drive/Colab Notebooks/AttGAN-Tensorflow/dataset/data'

i also changed it to
'/content/gdrive/My Drive/Colab Notebooks/AttGAN-Tensorflow/data'

then also getting same error

There shouldn't be any parameters for the data path. We should follow the below instruction,

image

shbnm21 commented 4 years ago

Intially I put images into data folder as u mentioned in readme.

But then also I was getting that error

So I created dataset folder in that I created data folder and then kept the images (it's same ) But I was getting same error.

shbnm21 commented 4 years ago

hello, i successfully tested the project,the error was coming because i was not using all the images.when i used all the images it ran successfully.

I have one more question how to check input and ouput nodes on tensorboard

Another question is do u have any idea how to convert checkpoint file to protobuf file(.pb file) I tried to convert STGAN model to .pb but getting parseerror

shbnm21 commented 4 years ago

where to check generated images after testing?

LynnHo commented 4 years ago

@shbnm21 for .pb file, use API below,

from tensorflow.python.framework import graph_util

with tf.gfile.GFile(py.join(output_dir, 'generator.pb'), 'wb') as f:
    constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph_def, ['name_of_output_node'])
    f.write(constant_graph.SerializeToString())

The generated images are in the output folder.

shbnm21 commented 4 years ago

Thank u for the quick reply,and how to get output node name

LynnHo commented 4 years ago

@shbnm21 you can print the name of a tensor.

shbnm21 commented 4 years ago

Ok thank u

shbnm21 commented 4 years ago

I used following code to print tensor names from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file ckpt_path="/content/gdrive/My Drive/Colab Notebooks/AttGAN-Tensorflow/output/128_shortcut1_inject1none/checkpoints/Epoch(199)_(947of947).ckpt" print_tensors_in_checkpoint_file(file_name=ckpt_path, tensor_name='',all_tensors=True, all_tensor_names=True)

It has given all the tensor names along with their values for generator and descriminator

there is long list

here are few tensor_name: D/Conv/InstanceNorm/beta tensor_name: D/Conv/InstanceNorm/beta/Adam_1 tensor_name: D/Conv/weights tensor_name: D/Conv/weights/Adam_1 tensor_name: Gdec/Conv2d_transpose/BatchNorm/beta tensor_name: Gdec/Conv2d_transpose/BatchNorm/beta/Adam tensor_name: Gdec/Conv2d_transpose/BatchNorm/beta/Adam_1 tensor_name: Gdec/Conv2d_transpose/BatchNorm/gamma tensor_name: Gdec/Conv2d_transpose/BatchNorm/gamma/Adam tensor_name: Gdec/Conv2d_transpose/BatchNorm/gamma/Adam_1

which one to use?

LynnHo commented 4 years ago

You should choose the tensor you want then print the name of that tensor.

shbnm21 commented 4 years ago

Can u please provide any script to print output node name. I didn't find any .

All I find needs .pb file or .pbtxt file

According to my understanding of Gan model,I need to find output layer of discriminator for output node. But I have a question In gan model both generator and discriminators are trained

So don't we need output nodes of both generator and discriminator

LynnHo commented 4 years ago

@shbnm21 For example,

https://github.com/LynnHo/AttGAN-Tensorflow/blob/4b00e6cb8d315564b403cad186e438c80cb5b0f5/test.py#L70

If you want to output x_sample in your .pb model, print its name by x_sample.name.

Or you can use x_sample_rename = tf.identity(x_sample, name='new_name') to rename it.

shbnm21 commented 4 years ago

Thanks a ton.

shbnm21 commented 4 years ago

Hello I have a question.this project tests images from 182637 to onwards.

If I want to test any random image .

For example if I want to test image 097000 and 098000 or any image from the data Then what changes I need to make in the code.