用于开发内存高效的深层可逆网络的pytorch框架。
memcnn的Python项目详细描述
一种用于开发高效记忆可逆神经网络的PyTorch框架。
- 自由软件:MIT license(如果你使用我们的作品,请引用我们的作品)
- 文档:https://memcnn.readthedocs.io。
- 安装:https://memcnn.readthedocs.io/en/latest/installation.html
功能
- 将任意pytorch模块包装并转换为可逆版本的简单包装类。
- 简单切换加法和仿射可逆耦合方案和不同实现。
- 通过设置reversibleblock的keep\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的可用值是cifar10和cifar100。
- MODEL的可用值是resnet32,resnet110,resnet164,revnet38,revnet110,revnet164
- 使用--fresh标志删除以前的实验结果。
- 使用--no-cuda标记在CPU上训练,而不是通过CUDA在GPU上训练。
如果数据集不可用,则会自动下载它们。
当使用python 3.*时,用适当的python3指令替换python指令。例如,当使用memcnn docker图像时,请使用python3.6。
当使用pip或从源安装memcnn时,可能需要在运行此命令之前设置配置文件。 请在此处阅读有关如何执行此操作的相应部分:https://memcnn.readthedocs.io/en/latest/installation.html