Model trainer: Add provisional colouration

[?]
Jul 7, 2021, 12:07 AM
ABITXOUUKIF3XVFXVOQ5YI7N43TS5OEVNEFUQ5Q7J4QEILFG3IPAC

Dependencies

  • [2] FYOPJXOX Model trainer: North/South comprise the Z axis in the source data
  • [3] CWOSQTC4 Trust tensorflow's thread safety (it wasn't the cause of an earlier bug)
  • [4] QMNTEX7P Try a loss function that has higher values for errors near sea level
  • [5] 2ABZP2KN Model trainer: save map.png after training
  • [6] ROQCAPZJ Begin function for showing the map (for now just opens SDL window)
  • [7] IGYI5RVV Figure out how to draw on the sdl2 window
  • [8] 6AXPZL5P Try to offload tight loop to rust (for now it segfaults)
  • [9] 4IXWCEHM Gamma correction
  • [10] ALMG52BO model trainer: speed up by waiting 15 seconds between monitor renders
  • [11] 7ML3OFE7 Model trainer: initial train and visualize thread pair (total crust mass; todo: altitude instead)
  • [*] E742MTJA Fix segfault (don't pass pointers between functions in different SDL versions), minor refactor
  • [*] 5AMZXFS5 model trainer: function to generate inputs to pass neural network for rendering equirectangular projection
  • [*] ZM2EMAZO Start doing python multi-module stuff properly

Change contents

  • edit in trainmodel/src/nativehelpers.py at line 14
    [14.532]
    native.colourize_heightmap.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int, ctypes.c_int]
    colourize_heightmap = native.colourize_heightmap
  • replacement in trainmodel/src/model.py at line 29
    [4.40][4.40:130]()
    y_true = tf.math.asinh(y_true - 4.94e-4)
    y_pred = tf.math.asinh(y_pred - 4.94e-4)
    [4.40]
    [4.130]
    y_true = tf.math.asinh(y_true - 0.1)
    y_pred = tf.math.asinh(y_pred - 0.1)
  • edit in trainmodel/src/helpers.rs at line 117
    [2.91]
    [14.1261]
    }
    }
    }
    #[no_mangle]
    pub extern "C" fn colourize_heightmap(target: *mut f64, source: *const f64, width: u32, height: u32) {
    const SEA_LEVEL: f64 = 0.1;
    let target = unsafe {
    std::slice::from_raw_parts_mut(target, (width as usize) * (height as usize) * 3)
    };
    let source = unsafe {
    std::slice::from_raw_parts(source, (width as usize) * (height as usize))
    };
    for y in 0 .. (height as usize) {
    let rowstart_s = y * (width as usize);
    let snow_line = {
    let y = (y as f64) / (height as f64);
    y * (1. - y) * 2.
    };
    for x in 0 .. (width as usize) {
    let ix = rowstart_s + x;
    let s = source[ix];
    let (r,g,b) = if s > snow_line {
    (1.,1.,1.)
    } else if s > SEA_LEVEL {
    let o = 0.9 * s;
    (o,0.9,o)
    } else {
    (0.,0.,0.9)
    };
    let ixt = ix * 3;
    target[ixt] = r;
    target[ixt + 1] = g;
    target[ixt + 2] = b;
  • replacement in trainmodel/src/drawmap.py at line 19
    [5.244][5.13:33]()
    last_rendered = 0
    [5.244]
    [5.235]
    last_rendered = -15
  • replacement in trainmodel/src/drawmap.py at line 23
    [3.41][5.0:100](),[5.127][5.0:100]()
    outputs = tf.math.multiply(255, tf.reshape(outputs ** 0.35, (512, 1024, outputs.shape[1])))
    [3.41]
    [5.219]
    outputs = tf.math.multiply(255, colourize_heightmap(tf.reshape(outputs, (512, 1024, outputs.shape[1]))))
  • edit in trainmodel/src/drawmap.py at line 46
    [5.914]
    def colourize_heightmap(source):
    shape = source.shape
    n = numpy.zeros((shape[0],shape[1],3), numpy.float64)
    source = tf.cast(source, tf.float64).numpy()
    helpers.colourize_heightmap(ctypes.cast(ctypes.c_voidp(n.ctypes.data), ctypes.POINTER(ctypes.c_double)), ctypes.cast(ctypes.c_voidp(source.ctypes.data), ctypes.POINTER(ctypes.c_double)), ctypes.c_int(shape[1]), ctypes.c_int(shape[0]))
    return tf.constant(n)
  • replacement in trainmodel/src/__main__.py at line 16
    [3.199][5.101:156](),[5.175][5.101:156]()
    outputs = tf.cast(outputs ** 0.35 * 255, tf.uint8)
    [3.199]
    [5.222]
    outputs = tf.cast(drawmap.colourize_heightmap(outputs) * 255, tf.uint8)