国立图书馆蟒蛇宾丁

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第三方库


热门话题
swing为什么不能在java类中隐藏JFrame   java编辑文本。getText()可能会产生NullPointerException   java通过蓝牙将字符串从PC作为客户端发送到移动服务器   从MySql表生成DAO的Pojo和JSP的java工具/Eclipse插件?   java不能调用匿名类方法   错误:更新Xss Eclipse后找不到或加载主类java   java Bukkit检查玩家的库存   java从FacesContext获取Webflow requestScope值   在SharedReferences中存储hashmap的java问题   Java奇怪的NullPointerException在反转链接列表时   java如何创建一个方法来获取hashmap中的值(字符串)的键   java如何在小程序的Eclipse中生成可执行JAR文件?   java如何将数组转换为字符串   java为什么我的日期不能正确设置为未来的30天?   php意外响应代码404凌空java 安卓   java使用JLists和vectors执行未经检查或不安全操作的两种情况   java SessionNotCreatedException:会话未创建:此版本的ChromeDriver仅支持使用Selenium ChromeDriver的Chrome版本77   java Google Maps API教程CurrentPlaceDetailsOnMap无法处理文件   java如何使用requestDispatcher重定向到jsp页面?