SemSegPipeline
SemSegPipeline copied to clipboard
INVALID_ARGUMENT: ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor
train_image_paths = [os.path.join(train_img_dir, x) for x in os.listdir(train_img_dir) if x.endswith('.png')]
train_mask_paths = [os.path.join(train_mask_dir, x) for x in os.listdir(train_mask_dir) if x.endswith('.png')]
print(train_image_paths[0:3])
print(train_mask_paths[0:3])
Which output:
['dataset/train_dir/uav_aerials/97.png', 'dataset/train_dir/uav_aerials/76.png', 'dataset/train_dir/uav_aerials/136.png']
['dataset/train_dir/uav_masks/97.png', 'dataset/train_dir/uav_masks/76.png', 'dataset/train_dir/uav_masks/136.png']
So I think the image and mask paths are correct.
My mask image is in RGB channel format, and the foreground color is (128,0,0)
color_list = [[0, 0, 0], [128, 0, 0]]
train_dl = DataLoader(image_paths=train_image_paths,
mask_paths=train_mask_paths,
image_size=(256,256),
channels=(3,3),
augment=True,
one_hot_encoding=True,
palette=color_list)
train_ds = train_dl.data_batch(batch_size=BATCH_SIZE,shuffle=True)
for image, mask in train_ds.take(1):
print(image,mask)
2022-04-24 09:40:55.352224: W tensorflow/core/framework/op_kernel.cc:1733] INVALID_ARGUMENT: ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.
Traceback (most recent call last):
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 269, in __call__
return func(device, token, args)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 147, in __call__
outputs = self._call(device, args)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 154, in _call
ret = self._func(*args)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 642, in wrapper
return func(*args, **kwargs)
File "/tmp/__autograph_generated_filenbagilbr.py", line 57, in _augmentation_func
ag__.if_stmt(ag__.ld(self).augment, if_body_1, else_body_1, get_state_1, set_state_1, ('image_f', 'mask_f'), 2)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 1321, in if_stmt
_py_if_stmt(cond, body, orelse)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 1374, in _py_if_stmt
return body() if cond else orelse()
File "/tmp/__autograph_generated_filenbagilbr.py", line 50, in if_body_1
ag__.if_stmt(ag__.ld(self).compose, if_body, else_body, get_state, set_state, ('image_f', 'mask_f'), 2)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 1321, in if_stmt
_py_if_stmt(cond, body, orelse)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 1374, in _py_if_stmt
return body() if cond else orelse()
File "/tmp/__autograph_generated_filenbagilbr.py", line 47, in else_body
(image_f, mask_f) = ag__.converted_call(ag__.ld(augment_func), (ag__.ld(image_f), ag__.ld(mask_f)), None, fscope_1)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 335, in converted_call
return _call_unconverted(f, args, kwargs, options, False)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 459, in _call_unconverted
return f(*args)
File "/home/ylzhao/project/potsdam_seg/dataloader.py", line 95, in _crop_random
h = tf.cast(shape[0] * self.crop_percent, tf.int32)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/framework/constant_op.py", line 102, in convert_to_eager_tensor
return ops.EagerTensor(value, ctx.device_name, dtype)
ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.
2022-04-24 09:40:55.369289: W tensorflow/core/framework/op_kernel.cc:1733] INVALID_ARGUMENT: ValueError: Tensor conversion requested dtype uint8 for Tensor with dtype float32: <tf.Tensor: shape=(256, 256, 2), dtype=float32, numpy=
array([[[1., 0.],
[1., 0.],
[1., 0.],
...,
[1., 0.],
[1., 0.],
[1., 0.]],
[[1., 0.],
[1., 0.],
[1., 0.],
...,
[1., 0.],
[1., 0.],
[1., 0.]],
[[1., 0.],
[1., 0.],
[1., 0.],
...,
[1., 0.],
[1., 0.],
[1., 0.]],
...,
[[1., 0.],
[1., 0.],
[1., 0.],
...,
[0., 1.],
[0., 1.],
[0., 1.]],
[[1., 0.],
[1., 0.],
[1., 0.],
...,
[0., 1.],
[0., 1.],
[0., 1.]],
[[1., 0.],
[1., 0.],
[1., 0.],
...,
[0., 1.],
[0., 1.],
[0., 1.]]], dtype=float32)>
Traceback (most recent call last):
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 269, in __call__
return func(device, token, args)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 147, in __call__
outputs = self._call(device, args)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 163, in _call
outputs = [
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 164, in <listcomp>
_maybe_copy_to_context_device(self._convert(x, dtype=dtype),
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 131, in _convert
return ops.convert_to_tensor(value, dtype=dtype)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/profiler/trace.py", line 183, in wrapped
return func(*args, **kwargs)
File "/home/ylzhao/anaconda3/envs/airbus/lib/python3.9/site-packages/tensorflow/python/framework/ops.py", line 1662, in convert_to_tensor
raise ValueError(
It's a bug when crop_percent argument is not specified, I will push a fix for it.
In the meantime you can try with:
train_dl = DataLoader(image_paths=train_image_paths,
mask_paths=train_mask_paths,
image_size=(256,256),
channels=(3,3),
augment=True,
one_hot_encoding=True,
crop_percent=0.9,
palette=color_list)