Файл: Направление подготовки 09. 03. 04 Программная инженерия.docx
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 29.10.2023
Просмотров: 220
Скачиваний: 2
ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.
False)
fake_mel_spec = G(video_frames, real_mel_spec) with torch.no_grad():
fake_outputs = D(video_frames, fake_mel_spec)
loss_from_D = loss_bce_gen(fake_outputs, real_labels)
loss_from_mel = loss_mce(fake_mel_spec, real_mel_spec)
G_loss = loss_from_D + TrainParams.ADDITIONAL_LOSS_COEFF * loss_from_mel G_optimizer.zero_grad()
G_loss.backward() G_optimizer.step()
if idx % 3 == 0 or idx == len(loader): progress_bar.set_description(
f”[{epoch + 1}/{TrainParams.EPOCHS}][{idx + 1}/{len(loader)}] ” f”real_loss: {real_loss} fake_loss: {fake_loss} ” f”loss_from_D: {loss_from_D} ”
f”loss_from_mel: {loss_from_mel} ” f”gen_loss: {G_loss}”
)
if idx % 15 == 0:
with torch.no_grad():
fake_mel_spec = G(video_frames, real_mel_spec) fig, (ax1, ax2) = plt.subplots(2)
fake = fake_mel_spec[0].to(’cpu’).numpy()
img = librosa.display.specshow(fake, y_axis=’linear’, ax=ax1) ax1.set(title=’Fake’)
fig.colorbar(img, ax=ax1, format=”%+2.f dB”)
real = real_mel_spec[0].to(’cpu’).numpy()
img = librosa.display.specshow(real, y_axis=’linear’, ax=ax2) ax2.set(title=’Real’)
fig.colorbar(img, ax=ax2, format=”%+2.f dB”)
plt.savefig(f’figures/{epoch}−{idx}.png’) plt.close()
if (epoch + 1) % 5 == 0:
torch.save(G, f’checkpoints/Generator_epoch_{epoch}.pth’) torch.save(D, f’checkpoints/Discriminator_epoch_{epoch}.pth’) print(f’{epoch} Model saved.’)
fake_mel_spec = G(video_frames, real_mel_spec) with torch.no_grad():
fake_outputs = D(video_frames, fake_mel_spec)
loss_from_D = loss_bce_gen(fake_outputs, real_labels)
loss_from_mel = loss_mce(fake_mel_spec, real_mel_spec)
G_loss = loss_from_D + TrainParams.ADDITIONAL_LOSS_COEFF * loss_from_mel G_optimizer.zero_grad()
G_loss.backward() G_optimizer.step()
if idx % 3 == 0 or idx == len(loader): progress_bar.set_description(
f”[{epoch + 1}/{TrainParams.EPOCHS}][{idx + 1}/{len(loader)}] ” f”real_loss: {real_loss} fake_loss: {fake_loss} ” f”loss_from_D: {loss_from_D} ”
f”loss_from_mel: {loss_from_mel} ” f”gen_loss: {G_loss}”
)
if idx % 15 == 0:
with torch.no_grad():
fake_mel_spec = G(video_frames, real_mel_spec) fig, (ax1, ax2) = plt.subplots(2)
fake = fake_mel_spec[0].to(’cpu’).numpy()
img = librosa.display.specshow(fake, y_axis=’linear’, ax=ax1) ax1.set(title=’Fake’)
fig.colorbar(img, ax=ax1, format=”%+2.f dB”)
real = real_mel_spec[0].to(’cpu’).numpy()
img = librosa.display.specshow(real, y_axis=’linear’, ax=ax2) ax2.set(title=’Real’)
fig.colorbar(img, ax=ax2, format=”%+2.f dB”)
plt.savefig(f’figures/{epoch}−{idx}.png’) plt.close()
if (epoch + 1) % 5 == 0:
torch.save(G, f’checkpoints/Generator_epoch_{epoch}.pth’) torch.save(D, f’checkpoints/Discriminator_epoch_{epoch}.pth’) print(f’{epoch} Model saved.’)