def test_graph_basic(self):
     from inferno.extensions.containers.graph import Graph
     from inferno.extensions.layers.convolutional import ConvELU2D
     from inferno.utils.model_utils import ModelTester
     # Build graph
     model = Graph()
     model.add_input_node('input_0')
     model.add_node('conv0', ConvELU2D(1, 10, 3), previous='input_0')
     model.add_node('conv1', ConvELU2D(10, 1, 3), previous='conv0')
     model.add_output_node('output_0', previous='conv1')
     ModelTester((1, 1, 100, 100), (1, 1, 100, 100))(model)
Exemple #2
0
    def __init__(self, in_channels, out_channels, size=3, kernel_size=3):
        super(ResBlock, self).__init__()
        self.in_channels = in_channels
        self.out_channels = out_channels
        self.size = size


        conv_ops = [ConvELU2D(kernel_size=kernel_size, in_channels=in_channels,   out_channels=out_channels)]
        for i in range(size-1):
            conv_ops.append(ConvELU2D(kernel_size=kernel_size, in_channels=out_channels,   out_channels=out_channels))

        self.conv_ops = nn.ModuleList(conv_ops)
Exemple #3
0
 def __init__(self, previous_in_channels, out_channels, kernel_size, pre_output):
     super(Xcoder, self).__init__()
     assert out_channels % 2 == 0
     self.in_channels = sum(previous_in_channels)
     self.out_channels = out_channels
     self.conv1 = ConvELU2D(
         in_channels=self.in_channels, out_channels=self.out_channels // 2, kernel_size=kernel_size
     )
     self.conv2 = ConvELU2D(
         in_channels=self.in_channels + (self.out_channels // 2),
         out_channels=self.out_channels // 2,
         kernel_size=kernel_size,
     )
     self.pre_output = pre_output
Exemple #4
0
 def test_graph_device_transfers(self):
     from inferno.extensions.containers.graph import Graph
     from inferno.extensions.layers.convolutional import ConvELU2D
     import torch
     # Build graph
     model = Graph()
     model.add_input_node('input_0')
     model.add_node('conv0', ConvELU2D(1, 10, 3), previous='input_0')
     model.add_node('conv1', ConvELU2D(10, 1, 3), previous='conv0')
     model.add_output_node('output_0', previous='conv1')
     # Transfer
     model.to_device('conv0', 'cpu').to_device('conv1', 'cuda', 0)
     x = torch.rand(1, 1, 100, 100)
     y = model(x)
     self.assertIsInstance(y.data, torch.cuda.FloatTensor)
Exemple #5
0
    def __init__(self, in_channels, out_channels,out_per_conv=4, size=4, kernel_size=3):
        super(DenseBlock, self).__init__()
        self.in_channels = in_channels
        self.out_channels = out_channels
        self.size = size

        sum_of_channels = int(in_channels)

        conv_ops = []
        for i in range(size):   

            if i + 1 == size:
                conv_ops.append(ConvELU2D(kernel_size=kernel_size, in_channels=sum_of_channels,   out_channels=out_channels))
                sum_of_channels += out_per_conv
            else:
                conv_ops.append(ConvELU2D(kernel_size=kernel_size, in_channels=sum_of_channels,   out_channels=out_per_conv))
                sum_of_channels += out_per_conv

        self.conv_ops = nn.ModuleList(conv_ops)
from inferno.io.box.cifar10 import get_cifar10_loaders
from inferno.trainers.basic import Trainer
from inferno.trainers.callbacks.logging.tensorboard import TensorboardLogger
from inferno.extensions.layers.convolutional import ConvELU2D
from inferno.extensions.layers.reshape import Flatten

# Fill these in:
LOG_DIRECTORY = 'logs'
SAVE_DIRECTORY = 'models'
DATASET_DIRECTORY = 'data'
DOWNLOAD_CIFAR = True
USE_CUDA = False

# Build torch model
model = nn.Sequential(
    ConvELU2D(in_channels=3, out_channels=256, kernel_size=3),
    nn.MaxPool2d(kernel_size=2, stride=2),
    ConvELU2D(in_channels=256, out_channels=256, kernel_size=3),
    nn.MaxPool2d(kernel_size=2, stride=2),
    ConvELU2D(in_channels=256, out_channels=256, kernel_size=3),
    nn.MaxPool2d(kernel_size=2, stride=2), Flatten(),
    nn.Linear(in_features=(256 * 4 * 4), out_features=10), nn.Softmax())

# Load loaders
train_loader, validate_loader = get_cifar10_loaders(DATASET_DIRECTORY,
                                                    download=DOWNLOAD_CIFAR)

# Build trainer
trainer = Trainer(model) \
  .build_criterion('CrossEntropyLoss') \
  .build_metric('CategoricalError') \