Spaces:
Build error
Build error
Update src/facerender/animate.py
Browse files127 unmodified lines128129130131132133134135136137138139140141142143144145146147148149150151152153154155156127 unmodified linesreturn checkpoint.get('epoch', 0)def _load_cpk_mapping(self, checkpoint_path, mapping=None, discriminator=None,optimizer_mapping=None, optimizer_discriminator=None, device='cpu'):if checkpoint_path.endswith(".tar"):try:with tarfile.open(checkpoint_path, "r") as tar:extract_dir = checkpoint_path.replace(".tar", "")os.makedirs(extract_dir, exist_ok=True)tar.extractall(path=extract_dir)checkpoint_path = os.path.join(extract_dir, "data.pkl")except Exception as e:print(f"Tar açma hatası: {e}")return 0checkpoint = torch.load(checkpoint_path, map_location=torch.device(device))if mapping is not None and 'mapping' in checkpoint:mapping.load_state_dict(checkpoint['mapping'])if discriminator is not None and 'discriminator' in checkpoint:discriminator.load_state_dict(checkpoint['discriminator'])if optimizer_mapping is not None and 'optimizer_mapping' in checkpoint:optimizer_mapping.load_state_dict(checkpoint['optimizer_mapping'])if optimizer_discriminator is not None and 'optimizer_discriminator' in checkpoint:optimizer_discriminator.load_state_dict(checkpoint['optimizer_discriminator'])return checkpoint.get('epoch', 0)127 unmodified lines128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166127 unmodified linesreturn checkpoint.get('epoch', 0)def load_cpk_mapping(self, checkpoint_path, mapping=None, discriminator=None,optimizer_mapping=None, optimizer_discriminator=None, device='cpu'):# Eğer dosya değil de klasörse ve içinde archive/data.pkl varsa onu yükleif os.path.isdir(checkpoint_path):archive_path = os.path.join(checkpoint_path, "archive", "data.pkl")if os.path.isfile(archive_path):print(f"📦 data.pkl bulundu: {archive_path}")checkpoint_path = archive_pathelse:raise FileNotFoundError("archive/data.pkl bulunamadı!")# Eğer tar dosyasıysa sadece kontrol amaçlı bakıyoruzelif checkpoint_path.endswith(".tar"):try:with tarfile.open(checkpoint_path, "r") as tar:members = tar.getnames()if not any("storages" in name for name in members):print("⚠️ 'storages' klasörü .tar içinde yok. Devam ediliyor...")except Exception as e:print(f"Tar kontrol hatası: {e}")# Yükleme işlemicheckpoint = torch.load(checkpoint_path, map_location=torch.device(device))if mapping is not None and 'mapping' in checkpoint:mapping.load_state_dict(checkpoint['mapping'])if discriminator is not None and 'discriminator' in checkpoint:discriminator.load_state_dict(checkpoint['discriminator'])if optimizer_mapping is not None and 'optimizer_mapping' in checkpoint:optimizer_mapping.load_state_dict(checkpoint['optimizer_mapping'])if optimizer_discriminator is not None and 'optimizer_discriminator' in checkpoint:optimizer_discriminator.load_state_dict(checkpoint['optimizer_discriminator'])return checkpoint.get('epoch', 0)
src/facerender/animate.py+35-25