# deeprobust.image.netmodels package

## Submodules

## deeprobust.image.netmodels.CNN module

This is an implementatio of a Convolution Neural Network with 2 Convolutional layer.

class `Net`(in_channel1=1, out_channel1=32, out_channel2=64, H=28, W=28)

  Model counterparts.

`test`(model, device, test_loader)

  test network.

  Parameters

    - model – model

    - device – device(option:’cpu’, ‘cuda’)

    - test_loader – testing data loader

`train`(model, device, train_loader, optimizer, epoch)

  train network.

  Parameters

    - model – model

    - device – device(option:’cpu’,’cuda’)

    - train_loader – training data loader

    - optimizer – optimizer

    - epoch – epoch

## deeprobust.image.netmodels.CNN_multilayer module

This is an implementation of Convolution Neural Network with multi conv layer.

class `Net`(in_channel1=1, out_channel1=32, out_channel2=64, H=28, W=28)

`test`(model, device, test_loader)

  test.

  Parameters

    - model – model

    - device – device

    - test_loader – test_loader

`train`(model, device, train_loader, optimizer, epoch)

  train.

  Parameters

    - model – model

    - device – device

    - train_loader – train_loader

    - optimizer – optimizer

    - epoch – epoch

## deeprobust.image.netmodels.YOPOCNN module

Model for YOPO.

### Reference

..[1]https://github.com/a1600012888/YOPO-You-Only-Propagate-Once

class `Net`(drop=0.5)

## deeprobust.image.netmodels.densenet module

This is an implementation of DenseNet model.

### Reference

..[1]Huang, Gao, Zhuang Liu, Laurens Van Der Maaten, and Kilian Q. Weinberger. “Densely connected convolutional networks.” In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 4700-4708. 2017. ..[2]Original implementation: https://github.com/kuangliu/pytorch-cifar

class `Bottleneck`(in_planes, growth_rate)

class `DenseNet`(block, nblocks, growth_rate=12, reduction=0.5, num_classes=10)

  DenseNet.

`DenseNet121`()

  DenseNet121.

`DenseNet161`()

  DenseNet161.

`DenseNet169`()

  DenseNet169.

`DenseNet201`()

  DenseNet201.

class `Transition`(in_planes, out_planes)

`densenet_cifar`()

  densenet_cifar.

`test`(model, device, test_loader)

  test.

  Parameters

    - model – model

    - device – device

    - test_loader – test_loader

`train`(model, device, train_loader, optimizer, epoch)

  train.

  Parameters

    - model – model

    - device – device

    - train_loader – train_loader

    - optimizer – optimizer

    - epoch – epoch

## deeprobust.image.netmodels.preact_resnet module

This is an reimplementaiton of Pre-activation ResNet.

class `PreActBlock`(in_planes, planes, stride=1)

  Pre-activation version of the BasicBlock.

class `PreActBottleneck`(in_planes, planes, stride=1)

  Pre-activation version of the original Bottleneck module.

class `PreActResNet`(block, num_blocks, num_classes=10)

  PreActResNet.

`PreActResNet18`()

  PreActResNet18.

## deeprobust.image.netmodels.resnet module

Properly implemented ResNet-s for CIFAR10 as described in paper [1].

This implementation is from Yerlan Idelbayev.

### Reference

..[1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun

  Deep Residual Learning for Image Recognition. arXiv:1512.03385

..[2] https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py

class `BasicBlock`(in_planes, planes, stride=1)

class `Bottleneck`(in_planes, planes, stride=1)

class `Net`(block, num_blocks, num_classes=10)

## deeprobust.image.netmodels.train_model module

This function help to train model of different archtecture easily. Select model archtecture and training data, then output corresponding model.

`train`(model, data, device, maxepoch, data_path='./', save_per_epoch=10, seed=100)

  train.

  Parameters

    - model – model(option:’CNN’, ‘ResNet18’, ‘ResNet34’, ‘ResNet50’, ‘densenet’, ‘vgg11’, ‘vgg13’, ‘vgg16’, ‘vgg19’)

    - data – data(option:’MNIST’,’CIFAR10’)

    - device – device(option:’cpu’, ‘cuda’)

    - maxepoch – training epoch

    - data_path – data path(default = ‘./’)

    - save_per_epoch – save_per_epoch(default = 10)

    - seed – seed

  Examples

  >>>import deeprobust.image.netmodels.train_model as trainmodel >>>trainmodel.train(‘CNN’, ‘MNIST’, ‘cuda’, 20)

## deeprobust.image.netmodels.train_resnet module

## deeprobust.image.netmodels.vgg module

This is an implementation of VGG net.

### Reference

..[1]Simonyan, Karen, and Andrew Zisserman. “Very deep convolutional networks for large-scale image recognition.” arXiv preprint arXiv:1409.1556 (2014). ..[2]Original implementation: https://github.com/kuangliu/pytorch-cifar

class `VGG`(vgg_name)

  VGG.

`test`(model, device, test_loader)

  test.

  Parameters

    - model – model

    - device – device

    - test_loader – test_loader

`train`(model, device, train_loader, optimizer, epoch)

  train.

  Parameters

    - model – model

    - device – device

    - train_loader – train_loader

    - optimizer – optimizer

    - epoch – epoch

## Module contents