代码段
python 代码段
Mr_Lowbee
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
pip3配置清华镜像源
将pip版本升级到>=10.0.0一行代码pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple原创 2019-11-27 11:48:22 · 2976 阅读 · 0 评论 -
PyTorch指定GPU训练 CUDA_VISIBLE_DEVICES
方法一import osimport torchos.environ["CUDA_VISIBLE_DEVICES"]="1, 2" 方法二CUDA_VISIBLE_DEVICES=1 python **.py原创 2021-06-03 21:16:35 · 1499 阅读 · 0 评论 -
从Tensor看图像
# 看tensor batch中的第一张图片kan = tensor[0:1, :, :, :].squeeze(0).squeeze(0).cpu()kan = T.ToPILImage()(kan)kan.show()原创 2021-01-18 21:33:42 · 353 阅读 · 2 评论 -
对图片加噪声
from PIL import Imageimport torchfrom torchvision import transforms as Tdef add_noise(input_img, noise_sigma): noise_sigma = noise_sigma / 255 noise_img = torch.clamp(input_img+noise_sigma*torch.randn_like(input_img), 0.0, 1.0) return no.原创 2020-08-13 20:12:05 · 770 阅读 · 0 评论 -
TV loss
class TVLoss(nn.Module): def __init__(self, TVLoss_weight=1): super(TVLoss, self).__init__() self.TVLoss_weight = TVLoss_weight def forward(self, x): batch_size = x.size()[0] h_x = x.size()[2] w_x = x.size()原创 2020-08-01 14:48:39 · 634 阅读 · 0 评论 -
rgb转gray
from PIL import Imagedata_root = './DIV2K_train_HR'data_save = './DIV2K_gray'for i in range(800): img_index = i + 1 print(img_index) img_rgb = Image.open(data_root + "/" + str(img_index).zfill(4)+'.png') img_gray = img_rgb.convert('L')原创 2020-07-24 16:11:28 · 262 阅读 · 0 评论 -
PIL从大图裁剪小图片
from PIL import Imageimport torchimport randomcrop_size = 128# 图片数量为200for i in range(200): print(i) img_index = random.randint(1, 800) # 大图的数量 img = Image.open('./DIV2K_gray' + "/" + str(img_index) + '.png') img_H = img.size[1]原创 2020-07-24 15:43:52 · 410 阅读 · 0 评论
分享