mirror of
https://github.com/facefusion/facefusion-labs.git
synced 2026-08-31 00:10:39 +02:00
Make validation step more solid, failed on empty checksums
This commit is contained in:
@@ -76,10 +76,15 @@ class FaceSwapperTrainer(lightning.LightningModule, FaceSwapperLoss):
|
|||||||
|
|
||||||
def validation_step(self, batch : Batch, batch_index : int) -> Tensor:
|
def validation_step(self, batch : Batch, batch_index : int) -> Tensor:
|
||||||
source_tensor, target_tensor, _ = batch
|
source_tensor, target_tensor, _ = batch
|
||||||
source_embedding = calc_id_embedding(self.id_embedder, source_tensor, (0, 0, 0, 0))
|
|
||||||
output_tensor, target_attributes = self.generator(target_tensor, source_embedding)
|
if torch.isnan(source_tensor).any() and torch.isnan(target_tensor).any():
|
||||||
output_embedding = calc_id_embedding(self.id_embedder, output_tensor, (0, 0, 0, 0))
|
source_embedding = calc_id_embedding(self.id_embedder, source_tensor, (0, 0, 0, 0))
|
||||||
validation = (nn.functional.cosine_similarity(source_embedding, output_embedding).mean() + 1) * 0.5
|
output_tensor, target_attributes = self.generator(target_tensor, source_embedding)
|
||||||
|
output_embedding = calc_id_embedding(self.id_embedder, output_tensor, (0, 0, 0, 0))
|
||||||
|
validation = (nn.functional.cosine_similarity(source_embedding, output_embedding).mean() + 1) * 0.5
|
||||||
|
else:
|
||||||
|
validation = torch.tensor(0.0)
|
||||||
|
|
||||||
self.log('validation', validation)
|
self.log('validation', validation)
|
||||||
return validation
|
return validation
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user