国立图书馆蟒蛇宾丁

nnutils-pytorch的Python项目详细描述


nnutils pytorch

Build Status

不同神经网络相关工具的pytorch绑定实现 CPU和GPU(CUDA)。

到目前为止,大多数实用程序都与我需要处理 不同的大小与填充分组成批。

包含的功能

自适应池

多个包(如torch或pytorch)中包含的自适应池层 假设批处理中的所有图像都具有相同的大小。这个实现 考虑批处理中每个单独图像的大小 (填充前)应用自适应池。

目前实施的平均和最大自适应池。

importtorchfromnnutils_pytorchimportadaptive_avgpool_2d,adaptive_maxpool_2d# Two random images, with three channels, 10 pixels height, 12 pixels widthx=torch.rand(2,3,10,12)# Matrix (N x 2) containing the height and width of each image.xs=torch.tensor([[10,6],[6,12],dtype=torch.int64)# Pool images to a fixed size, taking into account the original size of each# image before padding.## Output tensor has shape (2, 3, 3, 5)y1=adaptive_avgpool_2d(batch_input=x,output_sizes=(3,5),batch_sizes=xs)# Pool a single dimension of the images, taking into account the original# size of each image before padding. The None dimension is not pooled.## Output tensor has shape (2, 3, 5, 12)y2=adaptive_maxpool_2d(x,(5,None),xs)

重要:实现假定图像与 左上角。

按大小屏蔽图像

如果将不同大小的图像分组为填充有零的批, 可能需要在某些层之后/之前屏蔽输出/输入张量。 在这些情况下,这一层非常方便(并且有效)。

importtorchfromnnutils_pytorchimportmask_image_from_size# Two random images, with three channels, 10 pixels height, 12 pixels widthx=torch.rand(2,3,10,12)# Matrix (N x 2) containing the height and width of each image.xs=torch.tensor([[10,6],[6,12],dtype=torch.int64)# Note: mask_image_from_size is differentiable w.r.t. xy=mask_image_from_size(x,xs,mask_value=0)# mask_value is optional.

重要:实现假定图像与 左上角。

要求

  • python:2.7、3.5、3.6或3.7(使用版本2.7、3.5、3.6和3.7进行测试)。
  • PyTorch>;=1.1.0(使用版本1.1.0测试)。
  • C++ 11编译器(用GCC 4.82.5.5.0,4.4.0测试)。
  • 对于GPU支持:CUDA Toolkit

安装

假设您 已正确安装所需的库和工具。

安装过程从源代码处编译包,并使用 如果Pythorch有CUDA支持。

来自PYPI(推荐)

pip install nnutils-pytorch

您可能会发现已经为不同的python、cuda和cpu编译了这个包。 配置在:http://www.jpuigcerver.net/projects/nnutils-pytorch/whl/

例如,如果您想安装python 3.7的cpu版本:

pip install http://www.jpuigcerver.net/projects/nnutils-pytorch/whl/cpu/nnutils_pytorch-0.3.0-cp37-cp37m-linux_x86_64.whl

来自github

git clone https://github.com/jpuigcerver/nnutils.git
cd nnutils/pytorch
python setup.py build
python setup.py install

AVX512相关问题

使用CUDA和更新的主机编译器时可能会出现一些编译问题 使用AVX512指令。请安装gcc 4.9并将其用作主机 NVCC编译器。您可以简单地设置CCCXX环境变量 在生成/安装命令之前:

CC=gcc-4.9 CXX=g++-4.9 pip install nnutils-pytorch

或者(如果您使用的是github源代码):

CC=gcc-4.9 CXX=g++-4.9 python setup.py build

测试

安装库后,可以使用unittest进行测试。特别地, 运行以下命令:

python -m unittest nnutils_pytorch.adaptive_avgpool_2d_test
python -m unittest nnutils_pytorch.adaptive_maxgpool_2d_test
python -m unittest nnutils_pytorch.mask_image_from_size_test

所有测试都应通过(只有在支持时才执行CUDA测试)。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java语义理解递归反向字符串返回语句   java toString()方法打印空值   java大型IN子句   如何使用JavaSpring在JavaScriptjQuery中设置post路径   java ByteArrayOutputStream已上载到服务器   java为什么轮询在SocketIO上获取数据“无法加载请求的项”?   java源代码应该以UTF8格式保存   Java数据库轮询器?   在Java中将double转换为float   java AccessDeniedException:C:\Windows\System32\drivers\etc\hosts