/images/avatar.jpg

我的个人博客

python学习笔记

map 函数 1 2 3 4 5 6 7 #map 函数 接收一个函数和一个序列 >>> def f(x): ... return x * x ... >>> r = map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> list(r) [1, 4, 9, 16, 25, 36, 49, 64, 81] filter 函数 1 2 3 #filter 函数 #filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素。 匿名函数 1 2 3 4 5 6 7 #匿名函数 lambda x:x*x #等价于 def f(x): return x*x #关键字lambda表示匿名函数,冒号前面的x表示函数参数。 #匿名函数有个限制,就是只能有一个表达式,不用写return,返回值就是该表达式的结果。 函数的装饰器 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #首先需要明确函数可以作为参数传递给其他函数 #函数也可以作为其他函数的返回值 #装饰器的作用就是为已经存在的对象添加额外的功能。 #简单的装饰器使用 def use_logging(func): def wrapper(): print('nihao') return func() # 把 foo 当做参数传递进来时,执行func()就相当于执行foo() return wrapper def foo(): print('i am foo') foo = use_logging(foo) # 因为装饰器 use_logging(foo) 返回的时函数对象 wrapper,这条语句相当于 foo = wrapper foo() # 执行foo()就相当于执行 wrapper() >>nihao i am foo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # @ 符号就是装饰器的语法糖,它放在函数开始定义的地方,这样就可以省略最后一步再次赋值的操作。 def use_logging(func): def wrapper(): print('nihao') return func() return wrapper @use_logging def foo(): print("i am foo") foo() >>nihao i am foo #如上所示,有了 @ ,我们就可以省去foo = use_logging(foo)这一句了,直接调用 foo() 即可得到想要的结果。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #装饰器在 Python 使用如此方便都要归因于 Python 的函数能像普通的对象一样能作为参数传递给其他函数,可以被赋值给其他变量,可以作为返回值,可以被定义在另外一个函数内。 #可能有人问,如果我的业务逻辑函数 foo 需要参数怎么办?比如: def foo(name): print("i am %s" % name) 我们可以在定义 wrapper 函数的时候指定参数: def use_logging(func): def wrapper(*arg,**kw): print('nihao') return func(*arg,**kw) return wrapper @use_logging def foo(*arg,**kw): print("i am foo") foo() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #装饰器还有更大的灵活性,例如带参数的装饰器 def use_logging(level): def decorator(func): def wrapper(*args, **kwargs): if level == "warn": print('nihao') elif level == "info": print('china') return func(*args) return wrapper return decorator @use_logging(level="warn") def foo(name='foo'): print("i am %s" % name) foo() >>nihao i am foo #上面的 use_logging 是允许带参数的装饰器。它实际上是对原有装饰器的一个函数封装,并返回一个装饰器。我们可以将它理解为一个含有参数的闭包。当我 们使用@use_logging(level="warn")调用的时候,Python 能够发现这一层的封装,并把参数传递到装饰器的环境中。 @use_logging(level="warn") 等价于 @decorator 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #没错,装饰器不仅可以是函数,还可以是类,相比函数装饰器,类装饰器具有灵活度大、高内聚、封装性等优点。使用类装饰器主要依靠类的__call__方法,当使用 @ 形式将装饰器附加到函数上时,就会调用此方法。 class Foo(object): def __init__(self, func): self.

pytorch学习笔记

tensor的一些性质 1 2 3 4 5 import torch x=torch.tensor(2.5) print(x.dtype) >>torch.float32#torch默认的数据类型为float32 数据类型包括: 1 2 3 4 #如何将tensor的数据类型转换? #在Tensor后加 .long(), .int(), .float(), .double()等即可 x.half() >>tensor(2.5000, dtype=torch.float16) 1 2 3 4 5 6 7 #将numpy.ndarray转换为tensor: a=numpy.array([1,2,3]) a.dtype >>dtype('int32') t=torch.from_numpy(a) t >>tensor([1, 2, 3], dtype=torch.int32) 1 2 3 4 5 #torch.zeros_like(input)->生成一个与input相同size的零矩阵,同理还有torch.ones_like(input);torch.randn_like(input) input=torch.ones(2,3) torch.zeros_like(input) >>tensor([[0., 0., 0.], [0., 0., 0.]]) 1 2 3 4 5 6 #torch.

Semantic Hierarchy Emerges in Deep Generative Representations for Scene Synthesis

GAN的可解释性研究:从latent space出发 latent space的优点: 语义最高级-包含丰富的语义信息 维度比较低-比较好控制 可通过解码器生成image-可唯一确定image assumptions code连续变化时,生成图片也在连续变化-不会发生跳变 基于上一观点的基础上,latent space线性可分-可认为latent space中有一个超平面,latent code越过超平面后,相应的属性会发生变化。

Semantic Image Synthesis with Spatially-Adaptive Normalization

SPADE 为一个新颖的网络归一化层。 SPADE和AdaIN十分的相似,不同的是利用了batch norm进行归一化,类似的使用segmentation mask来提取调剂参数。这能够更好的保存segmentation mask的语义信息。 其中$\gamma_{c,y,x}^i(m)$和$\beta_{c,y,x}^i(m)$是归一化层的调剂参数,它与输入语义图有关并会随着位置$(y,x)$变化 SPADE生成器网络结构 why does the SPADE work better? 传统的生成器以segmentation mask(有不同的标签)直接作为网络的输入,经过卷积层和归一化层处理。无论输入的segmentation mask的标签的怎样的,当卷积层的输出经过归一化层处理后,其均值为0,因此其语义信息就会丢失。 而在SPADE中,语义图经过卷积操作映射成为调剂参数,而没有经过归一化层处理。仅仅只有上一层的激活值被归一化了。因此SPADE能够更好的保存语义信息。

SieveNet: A Unified Framework for Robust Image-Based Virtual Try-On

two-stage spatial-transformer - to capture fine details in the geometric iwarping stage conditional segmentation mask generation module - to prevent garment textures from bleeding onto skin and other areas. perceptual geometric matching loss - to impove warping output duelling triplet loss strategy - to improve output from the translation network inputs $I_P$ : try-on cloth image $I_{priors}$ : 19 channel pose and body-shape map

Soft-GatedWarping-GAN for Pose-Guided Person Image Synthesis

target parsing:在特定的segmentation 区域进行纹理的渲染 warping block :align the image features 通过仿射变换和TSP计算出transformation map用于warping condition image以减缓姿态不对齐问题 第一阶段生成目标姿态的part segmentation map 第二阶段首先训练geometric matcher 来估计condition segmentation和synthesized segmentation的transformation 参数。基于这个参数将condition image 的feature map进行warping,并渲染到target segmentation map warping GAN的好处:1)如果存在大的姿态变换就会进行大的transformation,小的姿态变形就会进行小的transformation 2)在feature-level进行warping,能够合成更加真实的图片 3)warping block 能够通过attention layers自动选择有效的feature map 进行warping Stage I: Pose-Guided Parsing 为了在part-level上学习condition image到target pose之间的映射,引入了pose-guide parser. Geometric Matcher 将仿射变换和TPS相结合,通过孪生卷积神经网络来获得transformation map。 首先估计condition segmentation 和synthesized segmentation之间的仿射参数,基于仿射变换参数,估计经过仿射变换后的warping result和target parsing之间的TPS参数。 提取出来的transformation map用于warping条件图像的feature,减缓不对齐问题。 Soft-gatedWarping-Block 网络结构 消融实验