A small isolated lighthouse on a scenic coast, with waves gently lapping against the rocks and a few seagulls circling in the sky, presents a peaceful natural scene.
4. 效果如下,是在图片作为视频的第一帧基础上体现提示词。
需要注意的是:这个功能需要订阅后才能使用
Prompt weight for preview Images
用于设置预览图像中提示词的权重,这一功能仅适用于图像生成而非视频生成。当设置较高的权重时,预览图像将更精准地呈现出输入的提示词内容。Negative Prompt for preview Images
用于设定预览图像中的否定提示词,帮助排除不需要的元素,提高生成内容的准确度。
Gen-3 是 Runway 在2024年6月18日推出的全新生成视频模型。作为 Gen-2 的继任者,Gen-3 引入了更先进的技术,在效率和图像生成效果上都得到了显著提升。 新推出的功能 相比 Gen-2,Gen-3 主要增强了以下功能:
通过对 Gen-2 和 Gen-3 两个模型文生视频的详细介绍,我们可以清楚地看到它们各自的优势和应用场景。Gen-2 模型凭借其免费使用和稳定的生成效果,已经足够满足初学者和一般创作者的需求。对于那些不需要过多高级功能的用户,Gen-2 是一个理想的选择。而 Gen-3 作为更高阶的模型,虽然功能还在不断完善中,但在生成速度、效果细节和处理复杂场景方面都有显著的提升,适合那些追求更高品质创作的用户。随着 Runway 的不断更新,我们可以期待 Gen-3 在未来会带来更多强大的功能和更广泛的应用场景。
import torch,torch.nn as nn,torch.optim as optim,cv2,numpy as np;class Generator(nn.Module):def __init__(self,z_dim,img_dim):super(Generator,self).__init__();self.gen=nn.Sequential(nn.Linear(z_dim,256),nn.LeakyReLU(0.2),nn.Linear(256,512),nn.LeakyReLU(0.2),nn.Linear(512,1024),nn.LeakyReLU(0.2),nn.Linear(1024,img_dim),nn.Tanh());def forward(self,x):return self.gen(x);class Discriminator(nn.Module):def __init__(self,img_dim):super(Discriminator,self).__init__();self.disc=nn.Sequential(nn.Linear(img_dim,1024),nn.LeakyReLU(0.2),nn.Linear(1024,512),nn.LeakyReLU(0.2),nn.Linear(512,256),nn.LeakyReLU(0.2),nn.Linear(256,1),nn.Sigmoid());def forward(self,x):return self.disc(x);z_dim,img_dim,lr,batch_size,epochs=100,64*64*3,0.0002,32,50000;generator=Generator(z_dim,img_dim);discriminator=Discriminator(img_dim);opt_gen,opt_disc=optim.Adam(generator.parameters(),lr=lr),optim.Adam(discriminator.parameters(),lr=lr);criterion=nn.BCELoss();def generate_noise(batch_size,z_dim):return torch.randn(batch_size,z_dim);def generate_video_frames(generator,z_dim,num_frames=30):frames=[];for _ in range(num_frames):noise=generate_noise(1,z_dim);frame=generator(noise).detach().numpy().reshape(64,64,3);frames.append((frame*255).astype(np.uint8));return frames;def save_video(frames,filename="output_video.mp4",fps=10):height,width,_=frames[0].shape;video=cv2.VideoWriter(filename,cv2.VideoWriter_fourcc(*'mp4v'),fps,(width,height));for frame in frames:video.write(cv2.cvtColor(frame,cv2.COLOR_RGB2BGR));video.release();for epoch in range(epochs):real_labels,fake_labels=torch.ones(batch_size,1),torch.zeros(batch_size,1);real_data=torch.randn(batch_size,img_dim);noise=generate_noise(batch_size,z_dim);fake_data=generator(noise);disc_real,disc_fake=discriminator(real_data).reshape(-1),discriminator(fake_data).reshape(-1);loss_disc_real,loss_disc_fake=criterion(disc_real,real_labels),criterion(disc_fake,fake_labels);loss_disc=(loss_disc_real+loss_disc_fake)/2;opt_disc.zero_grad();loss_disc.backward();opt_disc.step();output=discriminator(fake_data).reshape(-1);loss_gen=criterion(output,real_labels);opt_gen.zero_grad();loss_gen.backward();opt_gen.step();if epoch%100==0:print(f"Epoch [{epoch}/{epochs}] | Loss D: {loss_disc.item():.4f}, Loss G: {loss_gen.item():.4f}");if epoch%1000==0:frames=generate_video_frames(generator,z_dim);save_video(frames,f"generated_video_epoch_{epoch}.mp4");print("Training complete. Video generation finished.")
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有