large refactor
This commit is contained in:
+23
-3
@@ -5,12 +5,13 @@ import numpy as np
|
||||
import plotly.graph_objects as go
|
||||
import plotly.express as ex
|
||||
|
||||
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
|
||||
import tensorflow as tf
|
||||
import tensorflow_addons as tfa
|
||||
def fill(img, mask):
|
||||
coords = np.transpose(np.stack(np.nonzero((1 - mask))), (1,0))
|
||||
img_idx = np.transpose(np.stack(np.nonzero((mask))), (1,0))
|
||||
img_data = img[img_idx[:,0], img_idx[:,1], :]
|
||||
|
||||
interpolator = spi.NearestNDInterpolator(x=img_idx, y=img_data)
|
||||
img_2 = interpolator(coords)
|
||||
res = np.zeros((512,256,3), dtype=np.float32)
|
||||
@@ -19,6 +20,19 @@ def fill(img, mask):
|
||||
|
||||
return res
|
||||
|
||||
# @tf.function
|
||||
def fill_tf(img, mask):
|
||||
img = img[tf.newaxis,:,:,:]
|
||||
coords_int = tf.transpose(tf.stack(tf.experimental.numpy.nonzero(1-mask)), (1,0))
|
||||
coords = tf.cast(coords_int, dtype=tf.float32)
|
||||
img_2 = tfa.image.interpolate_bilinear(img, coords[tf.newaxis,:,:])
|
||||
# coords_2 = list(zip(tf.ones(coords_int.shape[0]), coords_int[:,0], coords_int[:,1]))
|
||||
# coords = tf.transpose(tf.stack([coords_int[:,0], coords_int[:,1]]))
|
||||
out = tf.tensor_scatter_nd_update(img[0], coords_int, img_2[0])
|
||||
|
||||
return out
|
||||
|
||||
|
||||
|
||||
def fill_label(img, mask):
|
||||
coords = np.transpose(np.stack(np.nonzero((1 - mask))), (1,0))
|
||||
@@ -44,7 +58,13 @@ def fill_uv_maps_posed_body(folder, type):
|
||||
id, _ = frame.split('_')
|
||||
# mask = np.load(os.path.join(folder, 'uv_mask', id + '.npz')); mask = mask['uv_mask']
|
||||
img = np.load(os.path.join(folder, type, frame)); img = img['uv_posed_body_no_orient']
|
||||
filled = fill(img, mask)
|
||||
# filled = fill(img, mask)
|
||||
img = np.zeros((100, 100, 3), dtype=np.float32)
|
||||
mask = np.zeros((100, 100), dtype=np.int32)
|
||||
img[25:75, 25:75, :] = 1
|
||||
mask[25:75, 25:75] = 1
|
||||
|
||||
filled = fill_tf(img, mask)
|
||||
np.savez_compressed(os.path.join(folder, type + '_filled', frame), uv_posed_body_no_orient_filled = filled)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user