神经网络风格迁移与生成对抗网络
1. 神经网络风格迁移
1.1 损失计算与辅助函数
内容损失是输入图像特征与目标输出图像特征之间的 L2 范数。通过最小化这些激活的 L2 范数,可使输出图像与输入图像具有相似的结构内容。最后将加权的风格损失和内容损失相加,得到组合损失。
以下是两个辅助函数:
@staticmethod
def clipPixels(image):
# clip any pixel values in the image falling outside the
# range [0, 1] and return the image
return tf.clip_by_value(image,
clip_value_min=0.0,
clip_value_max=1.0)
@staticmethod
def tensorToImage(tensor):
# scale pixels back to the range [0, 255] and convert the
# the data type of the pixels to integer
tensor = tensor * 255
tensor = np.array(tensor, dtype=np.uint8)
# remove the batch dimension from the image if it is
# present
超级会员免费看
订阅专栏 解锁全文
1066

被折叠的 条评论
为什么被折叠?



