0%

问题描述

在自建的conda环境之中使用pip安装会将库安装至base环境下,例如:

1
Requirement already satisfied: lmdb in ./.local/lib/python3.6/site-packages (1.2.1)

解决方案

首先切换至自建的conda环境

1
conda activate your_conda

使用
1
python -m pip install python_package

进行安装

错误提示

1
2
3
4
5
6
Enumerating objects: 4097, done.
Counting objects: 100% (4097/4097), done.
Delta compression using up to 4 threads
Compressing objects: 100% (764/764), done.
client_loop: send disconnect: Connection reset by peer/s
fatal: the remote end hung up unexpectedly | 42.00 KiB/s

错误原因

GitHub默认无法提交超过100M的文件

解决方案

将 Git 缓冲区大小增加到 repo 的最大单个文件大小

1
git config --global http.postBuffer 157286400

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

官方文档: torch.bmm(), version=1.2.0

torch.bmm()用于实现矩阵的乘法,其引用方式为:

1
2
3
4
5
6
torch.bmm(input, mat2, deterministic = False, out = None)
# 参数:
# !!!input和mat2的都需要是3-D tensor,即维度等于3
# input(Tensor): 第一个用于矩阵乘法的batch
# mat2(Tensor): 第二个用于矩阵乘法的batch
# out(Tensor, optional): 输出结果

除了需要满足inputmat2的维度一致,相似于线性代数的矩阵相乘,bmm()的矩阵乘法也约束了当input的维度为$(b\times n\times m)$,mat2的维度应为$(b\times m\times p)$,相乘结果out维度为$(b\times n\times p)$。

1
2
3
4
5
6
7
8
9
10
11
12
# example
import torch
# optional
out1 = torch.empty(0)
input = torch.randn(3,4,5)
mat2 = torch.randn(3,5,6)
# method 1
torch.bmm(input, mat2, out = out1)
# method 2
torch.bmm(input, mat2, out = mat2)
# method 3
out2 = torch.bmm(input, mat2)

版本:4.2.0

官方技术文档:hexo

换源

1
npm install -g cnpm --registry=https://registry.npm.taobao.org

next

1
2
cd <your_blog_dirname>
git clone https://github.com/theme-next/hexo-theme-next themes/next
1
2
3
vim <your_blog_dirname>/_config.yml
# 修改theme为next
theme: next

统计字数及阅读所需时间

1
2
3
# 安装hexo-symbols-count-time
cd <your_blog_dirname>
npm install hexo-symbols-count-time

如果没有配置symbols_count_time,将会使用默认配置,symbols_count_time配置如下:

1
2
3
4
5
6
7
8
9
10
# <your_blog_dirname>/_config.xml
symbols_count_time:
symbols: true # 统计单篇文章字数
time: true #计算阅读所需时间
total_symbols: true # 统计全部文章总计字数
total_time: true # 统计阅读全部文章所需时间
exclude_codeblock: false # 排除对代码块的计数
awl: 2 # CN ≈ 2\EN ≈ 5\RU ≈ 6
wpm: 275 # Slow ≈ 200\Normal ≈ 275\Fast ≈ 350
suffix: "mins." #若时间小于60分钟,将suffix作为后缀

在Next主题下集成了hexo-symbols-count-time,其配置选项如下:

1
2
3
4
5
# <your_blog_dirname>/theme/next/_config.yml
symbols_count_time:
separated_meta: true # 是否单独一行显示
item_text_post: true # 是否显示统计数据前的文字
item_text_total: false # 是否显示底部统计数据前的文字

参考材料:

​ [1] hexo-symbols-count-time 官方Github

​ [2] 启用字数和阅读时间预估

常用命令

对于learninggitbranch学习材料的总结。

Git Branch

1
2
3
4
5
6
7
8
9
10
# 先创建新分支,再进行切换
git branch <branch_name>
git checkout <branch_name>

# 创建新分支,同时切换到新创建的分支
git checkout -b <branch_name>


# 强制修改分支指向的位置,由<branch_name1>-><branch_name2>~[num]
git branch -f <branch_name1> <branch_name2>~[num]

Git Merge

当我们在新建的分支上完成开发任务后,开发完成需要合并回主线。

假设当前位于master分支,需要合并bugFix分支

1
git merge bugFix

Git Rebase

对提交的记录进行复制。

假设位于bugFix分支,需要合并到master分支

1
2
3
git rebase master
git checkout master
git rebase bugFix

Git Head

  1. Head的指向
1
2
3
4
5
6
7
8
9
10
11
# 查看HEAD的指向
cat .git/HEAD

# 若HEAD指向一个引用,可以使用如下方法查看指向
git symbolic-ref HEAD

# 将HEAD指向于<branch_name>的前一个位置
git checkout <branch_name>^

# 将HEAD指向于<branch_name>的第前[num]的位置
git checkout <branch_name>~[num]
  1. 分离的Head

    分离的Head指的是直接让HEAD指向具体的某个提交记录,而不是分支名,可以通过git log获取对应提交记录的哈希值。

1
2
3
# 假设当前HEAD为HEAD -> master -> C0(hash value)
git checkout C0
# 修改后的指向为HEAD -> C0

Git

ImageFolder

数据集结构:

root

dog

001.png

002.png

cat

001.png

002.png

函数调用

1
2
3
4
5
6
7
8
9
10
11
import torchvision.datasets as dset
# ImageFolder用于数据的加载,其调用方式为:
dset.ImageFolder(root, transform=None, target_transform=None, loader=<function default_loader>, is_valid_file=None)
'''
Parameters:
+root(srting)-图片的根目录
+transform(callable, optional)-将输入的PIL图像进行转换
+target_transform(callable, optional)-将target(label)进行转换
+loader(callable, optional)-对于给定的root路径,决定如何读取image。没有设定则为defaule loader,根据设置的_image_backend(默认'PIL')判断
+is_valid_file-用于检查文件
'''

transform示例

1
2
3
4
5
6
7
8
# transform callable variable example
transform = transforms.Compose([
transforms.RandomHorizontalFlip(), # 随机对图片继续水平翻转
transforms.Resize((self.img_size + 30, self.img_size + 30)),
transforms.RandomCrop(self.img_size), # 根据给定的size对Image进行随机裁剪
transforms.ToTensor(),
transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))
])

更多torchvision.transform操作。

Default loader

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# torchvision/datasets/folder.py
def pil_loader(path):
# open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
with open(path, 'rb') as f:
img = Image.open(f)
return img.convert('RGB')

def accimage_loader(path):
import accimage
try:
return accimage.Image(path)
except IOError:
# Potentially a decoding problem, fall back to PIL.Image
return pil_loader(path)

def default_loader(path):
from torchvision import get_image_backend
if get_image_backend() == 'accimage':
return accimage_loader(path)
else:
return pil_loader(path)

get_image_backend函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# torchvision/__init__.py
# 通过torchvision.set_image_backend设置image backend,默认设置为'PIL'
from torchvision import models
from torchvision import datasets
from torchvision import ops
from torchvision import transforms
from torchvision import utils
from torchvision import io

try:
from .version import __version__ # noqa: F401
except ImportError:
pass

_image_backend = 'PIL'

def set_image_backend(backend):
"""
Specifies the package used to load images.

Args:
backend (string): Name of the image backend. one of {'PIL', 'accimage'}.
The :mod:`accimage` package uses the Intel IPP library. It is
generally faster than PIL, but does not support as many operations.
"""
global _image_backend
if backend not in ['PIL', 'accimage']:
raise ValueError("Invalid backend '{}'. Options are 'PIL' and 'accimage'"
.format(backend))
_image_backend = backend

def get_image_backend():
"""
Gets the name of the package used to load images
"""
return _image_backend

Paper link: Perceptual Losses for Real-Time Style Transfer and Super-Resolution, ECCV2016

Authors: Justin Johnson, Alexandre Alahi, Li Fei-Fei

Problems

  1. the per-pixel losses used by these methods do not capture perceptual differences between output and ground-truth images.

  2. high-quality images can be generated using perceptual loss functions based not on differences between pixels but instead on differences between high-level image feature representations extracted from pretrained convolutional neural networks.

These approaches produce high-quality images, but are slow since inference requires solving an optimization problem.

Idea

​ we combine the benefits of these two approaches. We train feed forward transformation networks for image transformation tasks, but rather than using per-pixel loss functions depending only on low-level pixel information, we train our networks using perceptual loss functions that depend on high-level features from a pretrained loss network.

Method

fig2

loss functions

  1. feature reconstruction loss $\ell_{feat}^\phi$

  2. style reconstruction loss $\ell_{style}^\phi$

    In order to compute efficiently, reshaping $\phi_j(x)$ into a matrix $\psi$ of shape $C_j\times H_jW_j$, and then $G_j^\phi(x)=\psi\psi^T/C_jH_jW_j$

    The style reconstruction loss is then the squared Frobenius norm of the difference between the Gram matrices of the output and target images:

  3. pixel Loss

  4. Total Variation Regularization $\ell_{TV}(\hat{y})$

  1. Loss

Experiments

Style Transfer

goal

​ To generate an image $\hat{y}$ that combines the content of a target content image $y_c$ with the style of the a style style image $y_s$.

single-image super-resolution

​ The take is to generate a high-resolution output image from a low-resolution input

Future

​ In future work we hope to explore the use of perceptual loss functions for other image transformation tasks, such as colorization and semantic segmentation. We also plan to investigate the use of different loss networks to see whether for example loss networks trained on different tasks or datasets can impart image transformation networks with different types of semantic knowledge.