Skip to content

Instantly share code, notes, and snippets.

@funwarioisii
Created November 12, 2019 03:16
Show Gist options
  • Save funwarioisii/1abad9de0875dab3a155c8c2bb0fdc8a to your computer and use it in GitHub Desktop.
Save funwarioisii/1abad9de0875dab3a155c8c2bb0fdc8a to your computer and use it in GitHub Desktop.

tf.dataでtf.condが使えない

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_imagechannel=3は確定しているが,この時点ではwidthやheightは評価されてない

実行時に処理してほしいが,そうもいかないらしい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment