- #1
BRN
- 108
- 10
Hello everyone,
I have this problem that I can't solve:
I have two types of images contained in two different folders. I have to create a dataset with these images and train a cycleGAN model, but for simplicity we assume that I want to print them on monitor and forget the cycleGAN.
My code is this:
I receive this error:
I don't understand what the problem is, but I think it is due to how the dataset is created.
How can it be resolved?
Thank you all.
I have this problem that I can't solve:
I have two types of images contained in two different folders. I have to create a dataset with these images and train a cycleGAN model, but for simplicity we assume that I want to print them on monitor and forget the cycleGAN.
My code is this:
load and print:
input_path_A = './data/img_test_A/'
input_path_B = './data/img_test_B/'
EPOCHS = 50
buffer_size = 1000
batch_size = 2
def load_and_norm(filename):
img = tf.io.read_file(filename)
img = tf.cast(img, tf.float32) / 127.5 - 1 # normalization to [-1, 1]
return img
def load_dataset(ds_folder, batch_size, buffer_size):
img_filenames = tf.data.Dataset.list_files(os.path.join(ds_folder, "*.png"))
img_dataset = img_filenames.map(load_and_norm)
img_dataset = img_dataset.batch(batch_size).shuffle(buffer_size)
return img_dataset
def show_img(dataset1, dataset2):
iterator1 = iter(dataset1)
iterator2 = iter(dataset2)
num_rows = 4
num_cols = 2
fig, axs = plt.subplots(num_rows, num_cols, figsize=(10, 10))
axs = axs.flatten()
for i in range(num_rows*num_cols):
image1 = next(iterator1)
image2 = next(iterator2)
axs[i].imshow(image1)
axs[i+num_cols].imshow(image2)
plt.show()
I receive this error:
error:
2023-03-20 18:37:30.450694: W tensorflow/core/framework/op_kernel.cc:1722] OP_REQUIRES failed at cast_op.cc:121 : UNIMPLEMENTED: Cast string to float is not supported
---------------------------------------------------------------------------
UnimplementedError Traceback (most recent call last)
/tmp/ipykernel_18739/534026073.py in <module>
2 print("Starting epoch", epoch + 1)
3
----> 4 for x, y in train_dataset:
5 show_img(x, y)
~/.local/lib/python3.9/site-packages/tensorflow/python/data/ops/dataset_ops.py in __iter__(self)
488 if context.executing_eagerly() or ops.inside_function():
489 with ops.colocate_with(self._variant_tensor):
--> 490 return iterator_ops.OwnedIterator(self)
491 else:
492 raise RuntimeError("`tf.data.Dataset` only supports Python-style "
~/.local/lib/python3.9/site-packages/tensorflow/python/data/ops/iterator_ops.py in __init__(self, dataset, components, element_spec)
724 "When `dataset` is provided, `element_spec` and `components` must "
725 "not be specified.")
--> 726 self._create_iterator(dataset)
727
728 self._get_next_call_count = 0
~/.local/lib/python3.9/site-packages/tensorflow/python/data/ops/iterator_ops.py in _create_iterator(self, dataset)
749 output_types=self._flat_output_types,
750 output_shapes=self._flat_output_shapes))
--> 751 gen_dataset_ops.make_iterator(ds_variant, self._iterator_resource)
752 # Delete the resource when this object is deleted
753 self._resource_deleter = IteratorResourceDeleter(
~/.local/lib/python3.9/site-packages/tensorflow/python/ops/gen_dataset_ops.py in make_iterator(dataset, iterator, name)
3239 return _result
3240 except _core._NotOkStatusException as e:
-> 3241 _ops.raise_from_not_ok_status(e, name)
3242 except _core._FallbackException:
3243 pass
~/.local/lib/python3.9/site-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
7105 def raise_from_not_ok_status(e, name):
7106 e.message += (" name: " + name if name is not None else "")
-> 7107 raise core._status_to_exception(e) from None # pylint: disable=protected-access
7108
7109
UnimplementedError: Cast string to float is not supported
[[{{node Cast}}]] [Op:MakeIterator]
I don't understand what the problem is, but I think it is due to how the dataset is created.
How can it be resolved?
Thank you all.