当前位置: 首页 > news >正文

动易的网站能否静态网站开发实例社区

动易的网站能否静态,网站开发实例社区,58同城泰安二手房出售信息,增加访客的网站我在上篇博客深入浅出 diffusion#xff08;1#xff09;#xff1a;白话 diffusion 原理#xff08;无公式#xff09;中介绍了 diffusion 的一些基本原理#xff0c;其中谈到了 diffusion 的加噪过程#xff0c;本文用pytorch 实现下到底是怎么加噪的。 import torch…         我在上篇博客深入浅出 diffusion1白话 diffusion 原理无公式中介绍了 diffusion 的一些基本原理其中谈到了 diffusion 的加噪过程本文用pytorch 实现下到底是怎么加噪的。 import torch import math import numpy as np from PIL import Image import requests import matplotlib.pyplot as plot import cv2def linear_beta_schedule(timesteps):linear schedule, proposed in original ddpm paperscale 1000 / timestepsbeta_start scale * 0.0001beta_end scale * 0.02return torch.linspace(beta_start, beta_end, timesteps, dtype torch.float64)def cosine_beta_schedule(timesteps, s 0.008):cosine scheduleas proposed in https://openreview.net/forum?id-NEXDKk8gZsteps timesteps 1t torch.linspace(0, timesteps, steps, dtype torch.float64) / timestepsalphas_cumprod torch.cos((t s) / (1 s) * math.pi * 0.5) ** 2alphas_cumprod alphas_cumprod / alphas_cumprod[0]betas 1 - (alphas_cumprod[1:] / alphas_cumprod[:-1])return torch.clip(betas, 0, 0.999)# 时间步(timestep)定义为1000 timesteps 1000# 定义Beta Schedule, 选择线性版本同DDPM原文一致当然也可以换成cosine_beta_schedule betas linear_beta_schedule(timestepstimesteps)# 根据beta定义alpha alphas 1. - betas alphas_cumprod torch.cumprod(alphas, axis0) sqrt_recip_alphas torch.sqrt(1.0 / alphas)# 计算前向过程 diffusion q(x_t | x_{t-1}) 中所需的 sqrt_alphas_cumprod torch.sqrt(alphas_cumprod) sqrt_one_minus_alphas_cumprod torch.sqrt(1. - alphas_cumprod)def extract(a, t, x_shape):batch_size t.shape[0]out a.gather(-1, t.cpu())return out.reshape(batch_size, *((1,) * (len(x_shape) - 1))).to(t.device)# 前向加噪过程: forward diffusion process def q_sample(x_start, t, noiseNone):if noise is None:noise torch.randn_like(x_start)cv2.imwrite(noise.png, noise.numpy()*255)sqrt_alphas_cumprod_t extract(sqrt_alphas_cumprod, t, x_start.shape)sqrt_one_minus_alphas_cumprod_t extract(sqrt_one_minus_alphas_cumprod, t, x_start.shape)print(sqrt_alphas_cumprod_t :, sqrt_alphas_cumprod_t)print(sqrt_one_minus_alphas_cumprod_t :, sqrt_one_minus_alphas_cumprod_t)return sqrt_alphas_cumprod_t * x_start sqrt_one_minus_alphas_cumprod_t * noise# 图像后处理 def get_noisy_image(x_start, t):# add noisex_noisy q_sample(x_start, tt)# turn back into PIL imagenoisy_image x_noisy.squeeze().numpy()return noisy_image...# 展示图像, t0, 50, 100, 500的效果 x_start cv2.imread(img.png) / 255.0 x_start torch.tensor(x_start, dtypetorch.float) cv2.imwrite(img_0.png, get_noisy_image(x_start, torch.tensor([0])) * 255.0) cv2.imwrite(img_50.png, get_noisy_image(x_start, torch.tensor([50])) * 255.0) cv2.imwrite(img_100.png, get_noisy_image(x_start, torch.tensor([100])) * 255.0) cv2.imwrite(img_500.png, get_noisy_image(x_start, torch.tensor([500])) * 255.0) cv2.imwrite(img_999.png, get_noisy_image(x_start, torch.tensor([999])) * 255.0)sqrt_alphas_cumprod_t : tensor([[[0.9999]]], dtypetorch.float64) sqrt_one_minus_alphas_cumprod_t : tensor([[[0.0100]]], dtypetorch.float64) sqrt_alphas_cumprod_t : tensor([[[0.9849]]], dtypetorch.float64) sqrt_one_minus_alphas_cumprod_t : tensor([[[0.1733]]], dtypetorch.float64) sqrt_alphas_cumprod_t : tensor([[[0.9461]]], dtypetorch.float64) sqrt_one_minus_alphas_cumprod_t : tensor([[[0.3238]]], dtypetorch.float64) sqrt_alphas_cumprod_t : tensor([[[0.2789]]], dtypetorch.float64) sqrt_one_minus_alphas_cumprod_t : tensor([[[0.9603]]], dtypetorch.float64) sqrt_alphas_cumprod_t : tensor([[[0.0064]]], dtypetorch.float64) sqrt_one_minus_alphas_cumprod_t : tensor([[[1.0000]]], dtypetorch.float64) 以下分别为原图t 0, 50, 100, 500, 999 的结果。 可见随着 t 的加大原图对应的比例系数减小噪声的强度系数加大t 500的时候隐约可见人脸轮廓t 999 的时候人脸彻底淹没在噪声里面了。
http://www.w-s-a.com/news/2988443/

相关文章:

  • 登陆网站怎么做网站安全的建设目标
  • 网站域名免费过期域名网站
  • 做电子购物网站需要申请wordpress页数显示无限函数
  • 武夷山市网站建设男女做羞羞完整版网站
  • asp网站关键词进不了wordpress
  • 河源网站页面优化ppt大连网站建设联合企邦
  • 哈尔滨建设工程批前公示单页面网站好优化吗
  • 佛山高端画册设计公司网站排名优化学习
  • 网络规划设计师教程第2版pdf柳州360优化
  • 织梦图片网站电力通信网网络架构
  • 官网网站系统有哪些做国际贸易的网站
  • 邯郸企业做网站费用wordpress工作发布时间
  • 网站建设公司怎么发展wordpress刷注册
  • 金融公司网站 htmlwordpress 标签搜索引擎
  • 在农村开个网站要多少钱用vs2017做网站
  • 电商网站设计平台四川省招标投标网公告
  • 柏枫谈做网站都需要学什么wordpress google ua code 是什么
  • 网站内链规划海西网站建设哪家好
  • 邮箱注册过的网站查询彩票网站该怎么建设
  • 郑州哪里可以做网站360浏览器网页版
  • 廉江网站制作网站首页qq在线咨询js
  • 做网站推广的工资新浪博客导入wordpress
  • 怎样在淘宝网做网站专业的深圳app定制开发
  • 昆明网站建设企业网站建设首选玖艺建站信得过
  • 那个网站做拍手比较好自定义标签wordpress
  • 成都专业做网站的公司有哪些潍坊模板建站定制网站
  • 用seo对网站做分析企业邮箱注册登录入口
  • 长宁网站制作营销案例100例小故事
  • 易语言对做网站有什么帮助家装设计网站开发
  • 长沙住房建设部网站网站是怎么做新手引导