首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

基于深度学习的图像生成方法,具体来说是使用了生成对抗网络(GAN)的变体架构进行图像生成任务 通过构建特定的网络结构和进行适当的

人工智能 4.38MB 20 需要积分: 1
立即下载

资源介绍:

基于深度学习的图像生成方法,具体来说是使用了生成对抗网络(GAN)的变体架构进行图像生成任务 通过构建特定的网络结构和进行适当的
import os import cv2 import torch import numpy as np import torch.nn as nn class ResBlock(nn.Module): def __init__(self, num_channel): super(ResBlock, self).__init__() self.conv_layer = nn.Sequential( nn.Conv2d(num_channel, num_channel, 3, 1, 1), nn.BatchNorm2d(num_channel), nn.ReLU(inplace=True), nn.Conv2d(num_channel, num_channel, 3, 1, 1), nn.BatchNorm2d(num_channel)) self.activation = nn.ReLU(inplace=True) def forward(self, inputs): output = self.conv_layer(inputs) output = self.activation(output + inputs) return output class DownBlock(nn.Module): def __init__(self, in_channel, out_channel): super(DownBlock, self).__init__() self.conv_layer = nn.Sequential( nn.Conv2d(in_channel, out_channel, 3, 2, 1), nn.BatchNorm2d(out_channel), nn.ReLU(inplace=True), nn.Conv2d(out_channel, out_channel, 3, 1, 1), nn.BatchNorm2d(out_channel), nn.ReLU(inplace=True)) def forward(self, inputs): output = self.conv_layer(inputs) return output class UpBlock(nn.Module): def __init__(self, in_channel, out_channel, is_last=False): super(UpBlock, self).__init__() self.is_last = is_last self.conv_layer = nn.Sequential( nn.Conv2d(in_channel, in_channel, 3, 1, 1), nn.BatchNorm2d(in_channel), nn.ReLU(inplace=True), nn.Upsample(scale_factor=2), nn.Conv2d(in_channel, out_channel, 3, 1, 1)) self.act = nn.Sequential( nn.BatchNorm2d(out_channel), nn.ReLU(inplace=True)) self.last_act = nn.Tanh() def forward(self, inputs): output = self.conv_layer(inputs) if self.is_last: output = self.last_act(output) else: output = self.act(output) return output class SimpleGenerator(nn.Module): def __init__(self, num_channel=32, num_blocks=4): super(SimpleGenerator, self).__init__() self.down1 = DownBlock(3, num_channel) self.down2 = DownBlock(num_channel, num_channel*2) self.down3 = DownBlock(num_channel*2, num_channel*3) self.down4 = DownBlock(num_channel*3, num_channel*4) res_blocks = [ResBlock(num_channel*4)]*num_blocks self.res_blocks = nn.Sequential(*res_blocks) self.up1 = UpBlock(num_channel*4, num_channel*3) self.up2 = UpBlock(num_channel*3, num_channel*2) self.up3 = UpBlock(num_channel*2, num_channel) self.up4 = UpBlock(num_channel, 3, is_last=True) def forward(self, inputs): down1 = self.down1(inputs) down2 = self.down2(down1) down3 = self.down3(down2) down4 = self.down4(down3) down4 = self.res_blocks(down4) up1 = self.up1(down4) up2 = self.up2(up1+down3) up3 = self.up3(up2+down2) up4 = self.up4(up3+down1) return up4 weight = torch.load('weight.pth', map_location='cpu') model = SimpleGenerator() model.load_state_dict(weight) model.eval() img = cv2.imread(r'input.jpg') image = img/127.5 - 1 image = image.transpose(2, 0, 1) image = torch.tensor(image).unsqueeze(0) output = model(image.float()) output = output.squeeze(0).detach().numpy() output = output.transpose(1, 2, 0) output = (output + 1) * 127.5 output = np.clip(output, 0, 255).astype(np.uint8) cv2.imwrite('output.jpg', output)

资源文件列表:

photo turn animation.zip 大约有4个文件
  1. photo turn animation/
  2. photo turn animation/AIpic.py 3.53KB
  3. photo turn animation/input.jpg 21.6KB
  4. photo turn animation/weight.pth 4.7MB
0评论
提交 加载更多评论
其他资源 2112312312321321
2112312312321321
解决mac安装key-patch安装报错
解决mac安装key-patch安装报错
android文心一言的一个demo
调用文心一言api的一个尝试
TinyMCE 7.3.0 插件 自动远程上传插件catchremoteimage
tinyMCE 7.0 版 远程图片自动本地化 插件 使用环境:tinymce 7.3.0,Ajax 上传,layer消息 需自己定义上传接口
gwyzpclgj.zip
gwyzpclgj.zip
gwyzpclgj.zip
交易流水证明_用于材料证明_20241106_212352.zip
交易流水证明_用于材料证明_20241106_212352.zip
八上期中复习音频.zip
八上期中复习音频.zip
笔记大全,目前写到了2024-11-6之前的,暂存
2024-11-6的所有笔记