From f25d1b5b1af6f1be6f6d7553c1c14e216eaba888 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 10 Mar 2023 19:13:32 +0000 Subject: [PATCH] dlr CHANGE: properly normalise the heightmap --- aimodel/src/lib/dataset/dataset_mono.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aimodel/src/lib/dataset/dataset_mono.py b/aimodel/src/lib/dataset/dataset_mono.py index 1d67b9c..9c5433d 100644 --- a/aimodel/src/lib/dataset/dataset_mono.py +++ b/aimodel/src/lib/dataset/dataset_mono.py @@ -40,10 +40,11 @@ def parse_item(metadata, output_size=100, input_size="same", water_threshold=0.1 if heightmap is not None: heightmap = tf.expand_dims(heightmap, axis=-1) - # NORMALLY, this wouldn't work 'cause you'd need to know the max of ALL frames, but here we only have a single frame. - heightmap_max = tf.math.reduce_max(heightmap) - heightmap_min = tf.math.reduce_min(tf.where(tf.math.less(heightmap, -500), heightmap, tf.fill(heightmap.shape, 0.0))) - heightmap = (heightmap - heightmap_min) / heightmap_max + norm = tf.keras.layers.Normalization(axis=None) + norm.adapt(heightmap) + # THIS IS (probably) OK, because BatchNorm also outputs mean=0 stddev=1, bias term shifts anyway + # Ref https://datascience.stackexchange.com/a/54383/86851 + heightmap = norm(heightmap) heightmap = tf.transpose(heightmap, [1, 0, 2]) # [width, height] → [height, width] def parse_item_inner(item):