Example #1
0
def test_add_method():
    model = Sequential()

    model.add(Dense(n_nodes=32, n_inputs=45))

    model.build()

    with pytest.raises(Exception):
        model.add(Dense(n_nodes=32, n_inputs=45))
Example #2
0
from torchvision import datasets, transforms

# Create a Sequential model Instance
model = Sequential()

#Build your network
model.add(Conv2D(input_shape=(1, 28, 28), filters=128, kernel_size=3))
model.add(ReLU())
model.add(Conv2D(filters=64, kernel_size=3))
model.add(ReLU())
model.add(Conv2D(filters=32, kernel_size=3))
model.add(ReLU())
model.add(Flatten())
model.add(Dense(n_nodes=10))

model.build()
model.compile(optimizer=SGD(),
              loss_function=CrossEntropyLoss(),
              metrics=["accuracy"])
print(model.summary())

#Get the MNIST dataset
train_set = torchvision.datasets.MNIST(root='./data',
                                       train=True,
                                       download=True,
                                       transform=transforms.Compose(
                                           [transforms.ToTensor()]))

# Load the dataset from pytorch's Dataloader function
train_loader = torch.utils.data.DataLoader(train_set, batch_size=1000)
#Get the data