model trainer: function to generate inputs to pass neural network for rendering equirectangular projection

[?]
Jul 5, 2021, 1:09 AM
5AMZXFS5GBD6DS64Q5RTY55U7LQDMDW776UHZK4HQPPXWSMO3MAQC

Dependencies

  • [2] E742MTJA Fix segfault (don't pass pointers between functions in different SDL versions), minor refactor
  • [3] ZRPV3GAJ Model trainer: Add function to make tensor of cartesian coordinates for drawing the map (equirectangular projection)
  • [4] 6AXPZL5P Try to offload tight loop to rust (for now it segfaults)
  • [5] ROQCAPZJ Begin function for showing the map (for now just opens SDL window)
  • [6] IGYI5RVV Figure out how to draw on the sdl2 window

Change contents

  • edit in trainmodel/src/drawmap.py at line 6
    [3.53]
    [3.13]
    import numpy
  • replacement in trainmodel/src/drawmap.py at line 17
    [3.71][3.71:127]()
    test_tensor = tf.constant([[[0,0,255]] * 1024] * 512)
    [3.71]
    [3.127]
    test_tensor = tf.math.scalar_mul(255, tf.keras.activations.sigmoid(inputs_equirectangular(1024, 512)))
  • edit in trainmodel/src/drawmap.py at line 32
    [3.442][3.442:443](),[3.443][3.38:407](),[3.742][3.742:743]()
    def inputs(width, height):
    def cartesian(x,y):
    x = x / width * math.pi
    y = y / height * math.pi
    return [math.sin(y) * math.cos(x), math.sin(y) * math.sin(x), math.cos(y)]
    def row(y):
    def c(x):
    return cartesian(x,y)
    return list(map(c, range(0, width)))
    return tf.constant(list(map(row, range(0, height))))
  • replacement in trainmodel/src/drawmap.py at line 33
    [3.278][2.89:90]()
    [3.278]
    [2.90]
    def inputs_equirectangular(width, height):
    n = numpy.zeros((height, width, 3), numpy.float64)
    helpers.equirectangular(ctypes.cast(ctypes.c_voidp(n.ctypes.data), ctypes.POINTER(ctypes.c_double)), ctypes.c_int(width), ctypes.c_int(height))
    return tf.constant(n)
  • edit in trainmodel/src/nativehelpers.py at line 7
    [2.359]
    [2.359]
  • edit in trainmodel/src/nativehelpers.py at line 10
    [2.523][2.523:524]()
  • edit in trainmodel/src/nativehelpers.py at line 12
    [2.562]
    native.equirectangular.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.c_int, ctypes.c_int]
    equirectangular = native.equirectangular
  • replacement in trainmodel/src/helpers.rs at line 100
    [3.4099][3.4099:4100]()
    [3.4099]
    #[no_mangle]
    pub extern "C" fn equirectangular(target: *mut f64, width: u32, height: u32) {
    use std::f64::consts::PI;
    let target = unsafe {
    std::slice::from_raw_parts_mut(target, (width as usize) * (height as usize) * 3)
    };
    for y in 0 .. (height as usize) {
    let rowstart = y * (width as usize) * 3;
    let yr = 0. - (y as f64) / (height as f64) * PI;
    let yrs = yr.sin();
    let yrc = yr.cos();
    for x in 0 .. (width as usize) {
    let xr = (x as f64) / (width as f64) * 2. * PI;
    let pixstart = rowstart + 3 * x;
    target[pixstart] = yrs * xr.sin();
    target[pixstart + 1] = yrs * xr.cos();
    target[pixstart + 2] = yrc;
    }
    }
    }