model trainer: function to generate inputs to pass neural network for rendering equirectangular projection
[?]
Jul 5, 2021, 1:09 AM
5AMZXFS5GBD6DS64Q5RTY55U7LQDMDW776UHZK4HQPPXWSMO3MAQCDependencies
- [2]
E742MTJAFix segfault (don't pass pointers between functions in different SDL versions), minor refactor - [3]
ZRPV3GAJModel trainer: Add function to make tensor of cartesian coordinates for drawing the map (equirectangular projection) - [4]
6AXPZL5PTry to offload tight loop to rust (for now it segfaults) - [5]
ROQCAPZJBegin function for showing the map (for now just opens SDL window) - [6]
IGYI5RVVFigure out how to draw on the sdl2 window
Change contents
- edit in trainmodel/src/drawmap.py at line 6
import numpy - replacement in trainmodel/src/drawmap.py at line 17
test_tensor = tf.constant([[[0,0,255]] * 1024] * 512)test_tensor = tf.math.scalar_mul(255, tf.keras.activations.sigmoid(inputs_equirectangular(1024, 512))) - edit in trainmodel/src/drawmap.py at line 32
def inputs(width, height):def cartesian(x,y):x = x / width * math.piy = y / height * math.pireturn [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
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
- edit in trainmodel/src/nativehelpers.py at line 10
- 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]
#[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;}}}