用于开发内存高效的深层可逆网络的pytorch框架。

memcnn的Python项目详细描述


CircleCI - Status master branchDocker - StatusDocumentation - Status master branchCodacy - Branch gradeCodecov - Status master branchPyPI - Latest releaseConda - Latest releasePyPI - ImplementationPyPI - Python versionGitHub - Repository license

一种用于开发高效记忆可逆神经网络的PyTorch框架。

功能

  • 将任意pytorch模块包装并转换为可逆版本的简单包装类。
  • 简单切换加法仿射可逆耦合方案和不同实现。
  • 通过设置reversibleblockkeep\u input属性,简单切换内存节省。
  • 使用memcnn再现revnet实验的训练和评估代码。
  • python v2.7和v3.6以及torch v0.4、v1.0和v1.1的ci测试,具有良好的代码覆盖率。

示例用法:reversibleblock

importtorchimporttorch.nnasnnimportmemcnn# define a new torch Module with a sequence of operations: Relu o BatchNorm2d o Conv2dclassExampleOperation(nn.Module):def__init__(self,channels):super(ExampleOperation,self).__init__()self.seq=nn.Sequential(nn.Conv2d(in_channels=channels,out_channels=channels,kernel_size=(3,3),padding=1),nn.BatchNorm2d(num_features=channels),nn.ReLU(inplace=True))defforward(self,x):returnself.seq(x)# generate some random input data (batch_size, num_channels, y_elements, x_elements)X=torch.rand(2,10,8,8)# application of the operation(s) the normal waymodel_normal=ExampleOperation(channels=10)Y=model_normal(X)# application of the operation(s) turned invertible using the reversible blockF=ExampleOperation(channels=10//2)model_invertible=memcnn.ReversibleBlock(F,coupling='additive',keep_input=True,keep_input_inverse=True)Y2=model_invertible(X)# The input (X) can be approximated (X2) by applying the inverse method of the reversible block on Y2X2=model_invertible.inverse(Y2)

运行pytorch实验

安装memcnn后运行:

python -m memcnn.train [MODEL][DATASET][--fresh][--no-cuda]
  • DATASET的可用值是cifar10cifar100
  • MODEL的可用值是resnet32resnet110resnet164revnet38revnet110revnet164
  • 使用--fresh标志删除以前的实验结果。
  • 使用--no-cuda标记在CPU上训练,而不是通过CUDA在GPU上训练。

如果数据集不可用,则会自动下载它们。

当使用python 3.*时,用适当的python3指令替换python指令。例如,当使用memcnn docker图像时,请使用python3.6

当使用pip或从源安装memcnn时,可能需要在运行此命令之前设置配置文件。 请在此处阅读有关如何执行此操作的相应部分:https://memcnn.readthedocs.io/en/latest/installation.html

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

推荐PyPI第三方库


热门话题
javascript生成两点之间的固定纬度和经度   java为什么不删除并重命名文件?   求数组的和   java在漂亮面孔中使用正则表达式   SOAP(java)中的Hello World。如何修复它?   java I获取应用程序生成错误,配置为“”的资源“attr/arc_position”的值重复   云基础环境中的Java SFTP客户端应用   谷歌应用程序引擎Java查询日期不正常?   java使用cancel按钮对JOptionPane InputDialog循环进行转义   java数字格式总是返回异常   xquery Java Saxon API以“追加”模式写入文件   java Azure函数在第二个插槽中没有响应   java在构建Play应用程序后向其添加动态依赖项   json如何使用Jackson mapper for java。木卫一。可序列化类型字段?