backup
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = "2"
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = "3"
|
||||
import tensorflow as tf
|
||||
|
||||
gpus = tf.config.experimental.list_physical_devices('GPU')
|
||||
@@ -24,6 +24,7 @@ from custom_utils.custom_utils import UV2Mesh, maskFacesBatch, _maskFaces
|
||||
from tensorboardX import SummaryWriter
|
||||
import plotly.graph_objects as go
|
||||
import plotly.express as ex
|
||||
from PIL import Image
|
||||
|
||||
from utils import str_to_bool
|
||||
from tf_utils import check_tf_version, allow_memory_growth, split_gpu_for_testing
|
||||
@@ -31,26 +32,22 @@ from load_models import load_generator, load_discriminator
|
||||
from losses import d_logistic, d_logistic_r1_reg, g_logistic_non_saturating, g_logistic_ns_pathreg, edge_loss, uv_mask_loss, bend_loss
|
||||
# from losses import collision_penalty as collision_penalty
|
||||
from losses import collision_loss as collision_penalty
|
||||
from convnext.models.convnext_tf import ConvNeXt, ConvNeXtReverse, Block
|
||||
from stylegan2_ae.generator import Generator
|
||||
from custom_utils.graph_utils import Reconstructor_V4_Decoder as GNNDecoder, sparse_to_tensor
|
||||
from custom_utils.graph_utils import Reconstructor_v2 as SimpleReconstructor
|
||||
from custom_utils.custom_utils import batch_to_dict, load_model
|
||||
from dataset import DatasetFactory, StaticDataset
|
||||
from custom_utils.custom_utils import batch_to_dict
|
||||
from custom_utils.smpl import SMPL
|
||||
from auto_encoder_body import AutoEncoder as BodyAE
|
||||
from auto_encoder_curv import AutoEncoder as CurvatureAE
|
||||
from auto_encoder_static import AutoEncoder as StaticAE
|
||||
from models.cvae import CVAE
|
||||
|
||||
|
||||
name='cvae_10_2'
|
||||
name='cvae_15'
|
||||
def init_wandb():
|
||||
run = wandb.init(project='vae', name=name,
|
||||
notes='learn offsets. smaller flattened latent vectors. with 25-85k pretraining. smaller batchsize. fixed balancing of reconst and kl loss for baseline.\
|
||||
new implementation for kl loss. no lr schedule. 25 jumpsuits, average reconst_loss before calculation, linearly increasing balancing, up to 1000 from 250.\
|
||||
offsets over average unposed garment. gamma balancing. remove global orientation (in posed body input and in pose_shape parameters. larger batchsize\
|
||||
add edge and collision (fixed) loss. rebalanced l1 loss. increasing edge and coll coeff. retrained body encoder with deoriented bodies \
|
||||
don\'t freeze encoders, lower lr')
|
||||
notes='learn offsets. smaller flattened latent vectors. with 25-85k pretraining. smaller batchsize. fixed balancing of reconst and kl loss for baseline. \
|
||||
new implementation for kl loss. no lr schedule. 25 jumpsuits, average reconst_loss before calculation, linearly increasing balancing, up to 1 from 0.1. \
|
||||
offsets over average unposed garment. remove global orientation (in posed body input and in pose_shape parameters. \
|
||||
retrained body encoder with deoriented bodies \
|
||||
use mean l2 loss. small batch. l2 * 1000, balancing to 1 from 0.01\
|
||||
fixed gender issue and retrained body encoder\
|
||||
remove shape from unposed garment')
|
||||
artifact = wandb.Artifact('code', type='code')
|
||||
artifact.add_file('cvae.py')
|
||||
artifact.add_file('dataset.py')
|
||||
@@ -61,14 +58,14 @@ don\'t freeze encoders, lower lr')
|
||||
uv2mesh = UV2Mesh(res=256)
|
||||
|
||||
def plot_3d(mesh_gt, mesh_pred_unposed, faces, collision, collision_faces, collision_color):
|
||||
mesh_pred_unposed[:,1] += 1
|
||||
collision[:,1] += 2
|
||||
mesh_pred_unposed[:,2] += 1
|
||||
collision[:,2] += 2
|
||||
fig = go.Figure(data=[
|
||||
go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x=mesh_gt[:,0],
|
||||
y=mesh_gt[:,1],
|
||||
z=mesh_gt[:,2],
|
||||
y=mesh_gt[:,2],
|
||||
z=mesh_gt[:,1],
|
||||
# i, j and k give the vertices of triangles
|
||||
i = faces[:,0],
|
||||
j = faces[:,1],
|
||||
@@ -77,8 +74,8 @@ def plot_3d(mesh_gt, mesh_pred_unposed, faces, collision, collision_faces, colli
|
||||
go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x=mesh_pred_unposed[:,0],
|
||||
y=mesh_pred_unposed[:,1],
|
||||
z=mesh_pred_unposed[:,2],
|
||||
y=mesh_pred_unposed[:,2],
|
||||
z=mesh_pred_unposed[:,1],
|
||||
# i, j and k give the vertices of triangles
|
||||
i = faces[:,0],
|
||||
j = faces[:,1],
|
||||
@@ -87,8 +84,8 @@ def plot_3d(mesh_gt, mesh_pred_unposed, faces, collision, collision_faces, colli
|
||||
go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x=collision[:,0],
|
||||
y=collision[:,1],
|
||||
z=collision[:,2],
|
||||
y=collision[:,2],
|
||||
z=collision[:,1],
|
||||
# i, j and k give the vertices of triangles
|
||||
i = collision_faces[:,0],
|
||||
j = collision_faces[:,1],
|
||||
@@ -108,151 +105,7 @@ def plot_3d(mesh_gt, mesh_pred_unposed, faces, collision, collision_faces, colli
|
||||
|
||||
return fig
|
||||
|
||||
class Bottleneck(tf.keras.Model):
|
||||
|
||||
def __init__(self, dim):
|
||||
super(Bottleneck, self).__init__()
|
||||
|
||||
self.bottleneck = tf.keras.Sequential(
|
||||
[Block(dim=dim, drop_path=0,
|
||||
layer_scale_init_value=1e-6, prefix=f'bottleneck{j}') for j in range(5)]
|
||||
)
|
||||
|
||||
def call(self, inputs, training=None):
|
||||
x = inputs
|
||||
|
||||
x = self.bottleneck(x, training=training)
|
||||
|
||||
return x
|
||||
|
||||
|
||||
class Encoder(tf.keras.Model):
|
||||
|
||||
def __init__(self, latent_dim):
|
||||
super(Encoder, self).__init__()
|
||||
|
||||
self.encoder = ConvNeXt(depths=[3, 3, 9, 3], dims=[32, 64, 128, 256], include_top=False)
|
||||
self.flatten = tf.keras.layers.Flatten()
|
||||
self.mean = tf.keras.layers.Dense(latent_dim)
|
||||
self.log_var = tf.keras.layers.Dense(latent_dim)
|
||||
|
||||
def call(self, inputs, training=None):
|
||||
x = inputs
|
||||
|
||||
x = self.encoder(x)
|
||||
x = self.flatten(x)
|
||||
mean = self.mean(x)
|
||||
log_var = self.log_var(x)
|
||||
|
||||
return mean, log_var
|
||||
|
||||
|
||||
class Decoder(tf.keras.Model):
|
||||
|
||||
def __init__(self):
|
||||
super(Decoder, self).__init__()
|
||||
|
||||
self.dense = tf.keras.layers.Dense(16 * 8 * 80)
|
||||
self.reshape = tf.keras.layers.Reshape((16, 8, 80))
|
||||
self.decoder = ConvNeXtReverse(depths=list(reversed([3, 3, 9, 3])), dims=list(reversed([256, 128, 64, 16])))
|
||||
|
||||
|
||||
def call(self, inputs, training=None):
|
||||
x = inputs
|
||||
|
||||
x = self.dense(x)
|
||||
x = self.reshape(x)
|
||||
x = self.decoder(x)
|
||||
|
||||
return x
|
||||
|
||||
|
||||
class CVAE(tf.keras.Model):
|
||||
|
||||
def __init__(self, latent_dim=128):
|
||||
super(CVAE, self).__init__()
|
||||
self.latent_dim = latent_dim
|
||||
|
||||
model : StaticAE = StaticAE()
|
||||
load_model(model, 'checkpoints/ae_static_3')
|
||||
self.static_enc = tf.keras.Sequential([model.encoder, model.bottleneck])
|
||||
# self.static_enc.trainable = False
|
||||
|
||||
model : BodyAE = BodyAE()
|
||||
load_model(model, 'checpoints/ae_body_5')
|
||||
self.body_enc = tf.keras.Sequential([model.encoder, model.bottleneck])
|
||||
# self.body_enc.trainable = False
|
||||
|
||||
model : CurvatureAE = CurvatureAE()
|
||||
load_model(model, 'checpoints/ae_curvature_6')
|
||||
self.curv_enc = tf.keras.Sequential([model.encoder, model.bottleneck])
|
||||
# self.curv_enc.trainable = False
|
||||
|
||||
self.encoder = Encoder(latent_dim)
|
||||
self.decoder = Decoder()
|
||||
|
||||
|
||||
# @tf.function
|
||||
def sample(self, uv_template, uv_body_posed, uv_curv, uv_mask, eps=None):
|
||||
if eps is None:
|
||||
eps = tf.random.normal(shape=(4, self.latent_dim))
|
||||
|
||||
uv_template = tf.tile(tf.transpose(uv_template, [1,2,0])[tf.newaxis,:,:,:], [4,1,1,1])
|
||||
uv_body_posed = tf.tile(tf.transpose(uv_body_posed, [1,2,0])[tf.newaxis,:,:,:], [4,1,1,1])
|
||||
uv_curv = tf.tile(uv_curv[tf.newaxis,:,:,:], [4,1,1,1])
|
||||
uv_mask = tf.tile(uv_mask[tf.newaxis,:,:], [4,1,1])
|
||||
|
||||
# uv_template, uv_body_posed = tf.transpose(uv_template, [0,2,3,1]), tf.transpose(uv_body_posed, [0,2,3,1])
|
||||
z_static = self.static_enc(uv_template)
|
||||
z_body = self.body_enc(uv_body_posed)
|
||||
z_curv = self.curv_enc(uv_curv)
|
||||
|
||||
z_cond = tf.concat([z_static, z_body, z_curv], axis=-1)
|
||||
z = tf.concat([eps, z_cond], axis=-1)
|
||||
|
||||
x = self.decoder(z)
|
||||
x = x + avg_jumpsuit[tf.newaxis,:,:,:]
|
||||
x = x * uv_mask[:,:,:,tf.newaxis]
|
||||
|
||||
return x
|
||||
|
||||
|
||||
def reparameterize(self, mean, logvar):
|
||||
eps = tf.random.normal(shape=mean.shape)
|
||||
return eps * tf.exp(logvar * .5) + mean
|
||||
|
||||
|
||||
def decode(self, z, apply_sigmoid=False):
|
||||
logits = self.decoder(z)
|
||||
if apply_sigmoid:
|
||||
probs = tf.sigmoid(logits)
|
||||
return probs
|
||||
return logits
|
||||
|
||||
|
||||
def call(self, inputs, training=None):
|
||||
uv_unposed, uv_template, uv_body_posed, uv_curv, uv_mask, uv_shaped_body = inputs
|
||||
uv_unposed, uv_template, uv_body_posed = tf.transpose(uv_unposed, [0,2,3,1]), tf.transpose(uv_template, [0,2,3,1]), tf.transpose(uv_body_posed, [0,2,3,1])
|
||||
z_static = self.static_enc(uv_template)
|
||||
z_body = self.body_enc(uv_body_posed)
|
||||
z_curv = self.curv_enc(uv_curv)
|
||||
|
||||
x = tf.concat([uv_unposed, uv_template, uv_body_posed, uv_curv], axis=-1)
|
||||
|
||||
mean, logvar = self.encoder(x)
|
||||
z = self.reparameterize(mean, logvar)
|
||||
z = tf.concat([z, z_static, z_body, z_curv], axis=-1)
|
||||
x = self.decoder(z)
|
||||
|
||||
|
||||
# x = tf.transpose(x, [0,3,1,2])
|
||||
# x = x * uv_mask[:,tf.newaxis,:,:]
|
||||
# x = tf.image.resize(x, (512, 256), tf.image.ResizeMethod.LANCZOS5)
|
||||
# x = x + tf.transpose(uv_shaped_body, [0,2,3,1])
|
||||
x = x + avg_jumpsuit[tf.newaxis,:,:,:]
|
||||
x = x * uv_mask[:,:,:,tf.newaxis]
|
||||
|
||||
return x, mean, logvar, z
|
||||
|
||||
|
||||
def log_normal_pdf(sample, mean, logvar, raxis=1):
|
||||
@@ -268,7 +121,7 @@ def kl_loss(mean, logvar):
|
||||
return kl_loss
|
||||
|
||||
|
||||
@tf.function
|
||||
# @tf.function
|
||||
def train_step(batch):
|
||||
|
||||
with tf.GradientTape() as tape:
|
||||
@@ -280,10 +133,15 @@ def train_step(batch):
|
||||
mesh_pred_posed = smpl.run_garment(batch['pose_shape'][:, :72], batch['pose_shape'][:, 72:], mesh_pred)
|
||||
mesh_orig = batch['mesh_unposed']
|
||||
|
||||
shape = batch['pose_shape'][:, 72:]
|
||||
gender = tf.cast(tf.greater_equal(shape[:, 10] , 0.5), tf.int32)
|
||||
shape_offsets = tf.stack([tf.gather(tf.tensordot(shape[i,:10][tf.newaxis, :], smpl.shapedirs[gender[i]], axes=[[1], [2]])[0,:,:], smpl.to_keep, axis=0) for i in range(shape.shape[0])])
|
||||
mesh_pred_posed = mesh_pred_posed + shape_offsets * batch['mesh_mask'][:,:,tf.newaxis]
|
||||
|
||||
e_loss = tf.reduce_mean(edge_loss(mesh_pred, mesh_orig, batch['mesh_mask']))
|
||||
c_loss = tf.reduce_mean(collision_penalty(mesh_pred_posed, batch['mesh_body_posed'], batch['mesh_mask']))
|
||||
l1_loss = tf.reduce_sum(tf.reduce_sum((tf.math.abs(tf.transpose(batch['uv_unposed'], [0,2,3,1]) - pred)), axis=-1) * batch['uv_mask'], axis=[1, 2])
|
||||
l2_loss = 1e3 * tf.reduce_mean(tf.reduce_sum(((tf.transpose(batch['uv_unposed'], [0,2,3,1]) - pred) ** 2), axis=-1) * batch['uv_mask'], axis=[1, 2])
|
||||
# ms_ssim = tf.image.ssim_multiscale(tf.transpose(pred, [0,2,3,1]) + 1, tf.transpose(batch['uv_unposed'], [0,2,3,1]) + 1, max_val=2)
|
||||
ms_ssim = tf.image.ssim_multiscale(pred + 1, tf.transpose(batch['uv_unposed'], [0,2,3,1]) + 1, max_val=3)
|
||||
# ms_ssim = tf.reduce_mean(tf.image.ssim_multiscale((tf.transpose(pred, [0,2,3,1]) + 1) * batch['uv_mask'][:,:,:,tf.newaxis], (tf.transpose(batch['uv_unposed'], [0,2,3,1]) + 1) * batch['uv_mask'][:,:,:,tf.newaxis], max_val=2))
|
||||
@@ -292,17 +150,18 @@ def train_step(batch):
|
||||
fft_loss_pc, fft_loss_pc_low, fft_loss_pc_high = 0,0,0 #fft_loss_per_channel(pred, batch['uv_unposed'])
|
||||
tv_loss = tf.image.total_variation(pred)
|
||||
|
||||
reconstr_loss = l1_loss / 4
|
||||
reconstr_loss = tf.reduce_mean(reconstr_loss) + reg_coeff *(e_loss + c_loss)
|
||||
reconstr_loss = l2_loss
|
||||
reconstr_loss = tf.reduce_mean(reconstr_loss)
|
||||
# logpx_z = -reconstr_loss
|
||||
# logpz = log_normal_pdf(z[:,:model.latent_dim], 0., 0.)
|
||||
# logqz_x = log_normal_pdf(z[:,:model.latent_dim], mean, logvar)
|
||||
# loss = -tf.reduce_mean(logpx_z + balancing_coeff * (logpz - logqz_x))
|
||||
kl = kl_loss(mean, logvar)
|
||||
loss = reconstr_loss / (2 * (gamma ** 2)) + balancing_coeff * kl
|
||||
loss = reconstr_loss + balancing_coeff * kl
|
||||
# loss = reconstr_loss + balancing_coeff * kl
|
||||
ms_ssim = tf.reduce_mean(ms_ssim)
|
||||
l1_loss = tf.reduce_mean(l1_loss)
|
||||
l2_loss = tf.reduce_mean(l2_loss)
|
||||
fft_loss = tf.reduce_mean(fft_loss)
|
||||
tv_loss = tf.reduce_mean(tv_loss)
|
||||
mean = tf.reduce_mean(mean)
|
||||
@@ -320,7 +179,7 @@ def train_step(batch):
|
||||
'train/fft_loss': fft_loss, 'train/euclid_error_reconst': metric_2, 'train/rfft_loss': rfft_loss, 'train/fft_oc_low': fft_loss_pc_low, 'train/fft_pc_high': fft_loss_pc_high,
|
||||
'train/fft_loss_per_channel': fft_loss_pc, 'train/euclid_error_posed': euclid_posed, 'train/reconstr_loss': reconstr_loss, 'train/tv_loss': tv_loss,
|
||||
'train/mean': mean, 'train/logvar': logvar, 'train/kl_loss': kl, 'train/reconst_loss_norm': reconstr_loss / (2 * (gamma ** 2)), 'train/var': np.e ** logvar,
|
||||
'train/reg_coeff': reg_coeff }
|
||||
'train/reg_coeff': reg_coeff, 'train/l2_loss': l2_loss }
|
||||
|
||||
|
||||
|
||||
@@ -384,7 +243,12 @@ def plot_everything(batch: dict, type: str):
|
||||
|
||||
body = batch['mesh_body_posed'].numpy()
|
||||
mesh_posed = smpl.run_garment(batch['pose_shape'][:, :72], batch['pose_shape'][:, 72:], mesh_pred).numpy()
|
||||
garment_posed = [mesh_posed[i, mask[i], :] for i in range(body.shape[0])]
|
||||
|
||||
shape = batch['pose_shape'][:, 72:]
|
||||
gender = tf.cast(tf.greater_equal(shape[:, 10] , 0.5), tf.int32)
|
||||
shape_offsets = tf.stack([tf.gather(tf.tensordot(shape[i,:10][tf.newaxis, :], smpl.shapedirs[gender[i]], axes=[[1], [2]])[0,:,:], smpl.to_keep, axis=0) for i in range(shape.shape[0])])
|
||||
|
||||
garment_posed = [mesh_posed[i, mask[i], :] + shape_offsets.numpy()[i, mask[i], :] for i in range(body.shape[0])]
|
||||
collision = [np.concatenate((body[i], garment_posed[i]), axis=0) for i in range(len(garment_posed))]
|
||||
collision_faces = [np.concatenate((F, faces[i] + 14475), axis=0) for i in range(len(garment_posed))]
|
||||
collision_color = [np.concatenate((np.ones_like(body[i], dtype=np.int32)*100, np.ones_like(garment_posed[i], dtype=np.int32)*230), axis=0) for i in range(len(garment_posed))]
|
||||
@@ -397,25 +261,25 @@ def plot_everything(batch: dict, type: str):
|
||||
return { **figs, **{ type + '/images': imgs, type + '/mean_hist': mean_hist, type + '/logvar_hist': logvar_hist } }
|
||||
|
||||
|
||||
def load_model(model, checkpoint):
|
||||
ckpt = tf.train.Checkpoint(model=model)
|
||||
manager = tf.train.CheckpointManager(ckpt, checkpoint, max_to_keep=1)
|
||||
ckpt.restore(manager.latest_checkpoint)
|
||||
|
||||
|
||||
def sample(folder):
|
||||
# run = wandb.init(project='vae_plots', name=folder.split('/')[-1])
|
||||
load_model(model,folder)
|
||||
count = 0
|
||||
for batch in dataset_train:
|
||||
batch = static_dataset_train.expand_batch(batch_to_dict(batch, signature_dynamic))
|
||||
uv_curvature = tf.one_hot(batch['uv_curvature'], 7)
|
||||
nr_of_samples=2
|
||||
|
||||
pred = model.sample(batch['uv_static'][0], batch['uv_body_posed'][0], uv_curvature[0], batch['uv_mask'][0])
|
||||
pred = model.sample(batch['uv_static'][0], batch['uv_body_posed'][0], uv_curvature[0], batch['uv_mask'][0], nr_of_samples=nr_of_samples)
|
||||
pose, shape = batch['pose_shape'][0, :72], batch['pose_shape'][0, 72:]
|
||||
pose, shape = tf.tile(pose[tf.newaxis,:], [4,1]), tf.tile(shape[tf.newaxis,:], [4,1])
|
||||
pose, shape = tf.tile(pose[tf.newaxis,:], [nr_of_samples,1]), tf.tile(shape[tf.newaxis,:], [nr_of_samples,1])
|
||||
|
||||
mesh_pred = uv2mesh(tf.transpose(pred, [0,3,1,2]))
|
||||
mesh_posed = smpl.run_garment(pose, shape, mesh_pred).numpy()
|
||||
mesh_orig = batch['mesh_posed'][0].numpy()
|
||||
mesh_orig_reposed = smpl.run_garment(pose[:1], shape[:1], batch['mesh_unposed'][:1]).numpy()[0]
|
||||
|
||||
body = batch['mesh_body_posed'][0].numpy()
|
||||
body_color = np.ones_like(body, dtype=np.int32)*100
|
||||
@@ -424,72 +288,110 @@ def sample(folder):
|
||||
mask = batch['mesh_mask'].numpy().astype(bool)[0]
|
||||
_, faces = _maskFaces(np.ones((14475, 3)), F, mask)
|
||||
|
||||
batch = 0
|
||||
|
||||
pred_zero = model.sample(batch['uv_static'][0], batch['uv_body_posed'][0], uv_curvature[0], batch['uv_mask'][0], nr_of_samples=nr_of_samples, zero_latent=True)
|
||||
mesh_pred_zero = uv2mesh(tf.transpose(pred_zero, [0,3,1,2]))
|
||||
mesh_posed_zero = smpl.run_garment(pose, shape, mesh_pred_zero).numpy()
|
||||
|
||||
|
||||
|
||||
|
||||
meshes = []
|
||||
meshes.append(go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x=mesh_orig[mask,0],
|
||||
y=mesh_orig[mask,1],
|
||||
z=mesh_orig[mask,2],
|
||||
x=mesh_orig_reposed[mask,0],
|
||||
y=mesh_orig_reposed[mask,2],
|
||||
z=mesh_orig_reposed[mask,1],
|
||||
# i, j and k give the vertices of triangles
|
||||
i = faces[:,0],
|
||||
j = faces[:,1],
|
||||
k = faces[:,2]
|
||||
))
|
||||
|
||||
for i in range(4):
|
||||
for i in range(nr_of_samples):
|
||||
x = mesh_posed[i][mask, :].copy()
|
||||
x[:, 1] += 1 * (i + 1)
|
||||
# x[:, 2] += 1 * (i + 1)
|
||||
x[:, 2] += 1
|
||||
meshes.append(go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x=x[:,0],
|
||||
y=x[:,1],
|
||||
z=x[:,2],
|
||||
y=x[:,2],
|
||||
z=x[:,1],
|
||||
# i, j and k give the vertices of triangles
|
||||
i = faces[:,0],
|
||||
j = faces[:,1],
|
||||
k = faces[:,2]
|
||||
))
|
||||
|
||||
for i in range(5):
|
||||
x = body.copy()
|
||||
x[:, 1] += 1 * i
|
||||
|
||||
for i in range(nr_of_samples):
|
||||
x = mesh_posed_zero[i][mask, :].copy()
|
||||
# x[:, 2] += 1 * (i + 1)
|
||||
x[:, 2] += 2
|
||||
meshes.append(go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x=x[:,0],
|
||||
y=x[:,1],
|
||||
z=x[:,2],
|
||||
y=x[:,2],
|
||||
z=x[:,1],
|
||||
# i, j and k give the vertices of triangles
|
||||
i = F[:,0],
|
||||
j = F[:,1],
|
||||
k = F[:,2],
|
||||
vertexcolor=body_color
|
||||
i = faces[:,0],
|
||||
j = faces[:,1],
|
||||
k = faces[:,2]
|
||||
))
|
||||
|
||||
# for i in range(5):
|
||||
# x = body.copy()
|
||||
# x[:, 2] += 1 * i
|
||||
# meshes.append(go.Mesh3d(
|
||||
# # 8 vertices of a cube
|
||||
# x=x[:,0],
|
||||
# y=x[:,2],
|
||||
# z=x[:,1],
|
||||
# # i, j and k give the vertices of triangles
|
||||
# i = F[:,0],
|
||||
# j = F[:,1],
|
||||
# k = F[:,2],
|
||||
# vertexcolor=body_color
|
||||
# ))
|
||||
|
||||
|
||||
fig = go.Figure(data=meshes)
|
||||
|
||||
fig.update_layout(scene_aspectmode='manual', scene_aspectratio=dict(x=1, y=3, z=1))
|
||||
fig.update_layout(scene_aspectmode='manual', scene_aspectratio=dict(x=1, y=2, z=1))
|
||||
# fig.update_layout(scene_aspectmode='manual', scene_aspectratio=dict(x=1, y=nr_of_samples-1, z=1))
|
||||
fig.update_layout(
|
||||
scene = dict(
|
||||
xaxis = dict(nticks=4, range=[-1,1],),
|
||||
yaxis = dict(nticks=4, range=[-1,5],),
|
||||
# yaxis = dict(nticks=4, range=[-1,nr_of_samples+1],),
|
||||
yaxis = dict(nticks=4, range=[-1,3],),
|
||||
zaxis = dict(nticks=4, range=[-1,1],),)
|
||||
)
|
||||
|
||||
# wandb.log({'plot_' + str(count): fig})
|
||||
fig.show()
|
||||
|
||||
pred = pred.numpy()
|
||||
frames = [Image.fromarray(((pred[i] + 1) * 128).astype(np.int8), mode='RGB') for i in range(pred.shape[0])]
|
||||
frames[0].save("temp/garment_1.gif", format="GIF", append_images=frames[1:],
|
||||
save_all=True, duration=500, loop=0)
|
||||
|
||||
|
||||
if count > 10:
|
||||
break
|
||||
|
||||
print(count)
|
||||
count += 1
|
||||
|
||||
print()
|
||||
|
||||
if __name__ == '__main__':
|
||||
# init_wandb()
|
||||
# allow_memory_growth()
|
||||
allow_memory_growth()
|
||||
parser = argparse.ArgumentParser(description='')
|
||||
parser.add_argument('--name', type=str)
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
batch_size = 12
|
||||
batch_size = 4
|
||||
|
||||
smpl = SMPL()
|
||||
|
||||
@@ -511,27 +413,30 @@ if __name__ == '__main__':
|
||||
'uv_shaped_body': (3, 512, 256,),
|
||||
}
|
||||
|
||||
dataset_train = factory.get_dataset(folder='/home/workspace/local-data/jumpsuit_20/train', batch_size=batch_size, signature=signature_dynamic)
|
||||
static_dataset_train = StaticDataset(folder='/home/workspace/local-data/jumpsuit_20/train', signature=signature_static)
|
||||
dataset_train = factory.get_dataset(folder='/home/workspace/local-data/train_100', batch_size=batch_size, signature=signature_dynamic)
|
||||
static_dataset_train = StaticDataset(folder='/home/workspace/local-data/train_100', signature=signature_static)
|
||||
dataset_valid = factory.get_dataset(folder='/home/workspace/local-data/jumpsuit_20/valid', batch_size=batch_size, signature=signature_dynamic)
|
||||
static_dataset_valid = StaticDataset(folder='/home/workspace/local-data/jumpsuit_20/valid', signature=signature_static)
|
||||
|
||||
|
||||
model = CVAE()
|
||||
model = CVAE(avg_garment_path='custom_data/jumpsuit_20_avg_uv.npy',
|
||||
latent_dim=128, static_model='checkpoints/ae_static_3',
|
||||
body_model='checpoints/ae_body_6',
|
||||
curvature_model='checpoints/ae_curvature_6')
|
||||
|
||||
|
||||
# lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(0.0001, decay_steps=30000, decay_rate=0.1, staircase=False)
|
||||
optimizer = tf.optimizers.Adam(learning_rate=0.0001)
|
||||
balancing_coeff = 250
|
||||
balancing_coeff = 0.0001
|
||||
reg_coeff = 1
|
||||
folder = 'models/ae_logs/'
|
||||
valid_iterator = iter(dataset_valid)
|
||||
gamma = 1
|
||||
balancing_activated_step = 0
|
||||
avg_jumpsuit = np.load('custom_data/jumpsuit_20_avg_uv.npy')
|
||||
# avg_jumpsuit = np.load('custom_data/jumpsuit_20_avg_uv.npy')
|
||||
|
||||
|
||||
sample('checkpoints/cvae_10')
|
||||
# sample('checkpoints/cvae_13')
|
||||
|
||||
|
||||
ckpt = tf.train.Checkpoint(model=model)
|
||||
@@ -561,9 +466,9 @@ if __name__ == '__main__':
|
||||
if train_loss['train/euclid_error'] < 0.01:
|
||||
if balancing_activated_step == 0:
|
||||
balancing_activated_step = step
|
||||
balancing_coeff = balancing_coeff + 1000 / 30000
|
||||
if train_loss['train/euclid_error'] < 0.015:
|
||||
reg_coeff = reg_coeff + 100 / 15000
|
||||
balancing_coeff = balancing_coeff + 1 / 15000
|
||||
# if train_loss['train/euclid_error'] < 0.015:
|
||||
# reg_coeff = reg_coeff + 100 / 15000
|
||||
# if step > 15000 and balancing_coeff <= 1e-3:
|
||||
# balancing_coeff = 1e-2
|
||||
# if step > 20000 and balancing_coeff <= 1e-3:
|
||||
|
||||
Reference in New Issue
Block a user