pathの集合(データセット)から前処理を経て,画像のデータセットを作りたい
all_image_path = load_image_path() # load image path
path_ds = tf.data.Dataset.from_tensor_slices(all_image_path)
image_ds = path_ds.map(load_and_preprocess_image)
ここで
def load_and_preprocess_image(path):
image = tf.io.read_file(p)
image = tf.image.decode_image(image, channel=3)
image = tf.cond(
image.shape[0] < image.shape[1],
lambda : tf.image.rot90(image),
lambda : image
)
return image
としていると,tf.cond
内のimage.shape[0]がNoneを返してfailする
image.shape=(None, None, 3)
となっていて,tf.image.decode_image
でchannel=3
は確定しているが,この時点ではwidthやheightは評価されてない
実行時に処理してほしいが,そうもいかないらしい