Ejemplo n.º 1
0
    cons.MaxNorm(5, 0, 'batch', 'conv*')
]
callbacks = [cbks.ReduceLROnPlateau(monitor='loss', verbose=1)]

trainer.compile(loss='nll_loss',
                optimizer='adadelta',
                regularizers=regularizers,
                constraints=constraints,
                callbacks=callbacks)

trainer.fit([x_train, x_train, x_train], [y_train, y_train, y_train],
            num_epoch=3,
            batch_size=128,
            verbose=1)

yp1, yp2, yp3 = trainer.predict([x_train, x_train, x_train])
print(yp1.size(), yp2.size(), yp3.size())

eval_loss = trainer.evaluate([x_train, x_train, x_train],
                             [y_train, y_train, y_train])
print(eval_loss)

# With multiple loss functions given
model = Network()
trainer = ModuleTrainer(model)

trainer.compile(loss=['nll_loss', 'nll_loss', 'nll_loss'],
                optimizer='adadelta',
                regularizers=regularizers,
                constraints=constraints,
                callbacks=callbacks)
Ejemplo n.º 2
0
        self.conv1 = nn.Conv2d(1, 32, kernel_size=3)
        self.conv2 = nn.Conv2d(32, 64, kernel_size=3)
        self.fc1 = nn.Linear(1600, 128)
        self.fc2 = nn.Linear(128, 1)

    def forward(self, x):
        x = F.relu(F.max_pool2d(self.conv1(x), 2))
        x = F.relu(F.max_pool2d(self.conv2(x), 2))
        x = x.view(-1, 1600)
        x = F.relu(self.fc1(x))
        x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        return th.abs(10 - x)


model = Network()
trainer = ModuleTrainer(model)

trainer.compile(loss='unconstrained_sum',
                optimizer='adadelta')

trainer.fit(x_train,
            num_epoch=3, 
            batch_size=128,
            verbose=1)

ypred = trainer.predict(x_train)
print(ypred.size())

eval_loss = trainer.evaluate(x_train, None)
print(eval_loss)
Ejemplo n.º 3
0
        x = F.relu(F.max_pool2d(self.conv2(x), 2))
        x = x.view(-1, 1600)
        x = F.relu(self.fc1(x))
        x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        return F.log_softmax(x), F.log_softmax(x)


# one loss function for multiple targets
model = Network()
trainer = ModuleTrainer(model)
trainer.compile(loss='nll_loss', optimizer='adadelta')

trainer.fit(x_train, [y_train, y_train],
            num_epoch=3,
            batch_size=128,
            verbose=1)
ypred1, ypred2 = trainer.predict(x_train)
print(ypred1.size(), ypred2.size())

eval_loss = trainer.evaluate(x_train, [y_train, y_train])
print(eval_loss)
# multiple loss functions
model = Network()
trainer = ModuleTrainer(model)
trainer.compile(loss=['nll_loss', 'nll_loss'], optimizer='adadelta')
trainer.fit(x_train, [y_train, y_train],
            num_epoch=3,
            batch_size=128,
            verbose=1)
        self.conv2 = nn.Conv2d(32, 64, kernel_size=3)
        self.fc1 = nn.Linear(1600, 128)
        self.fc2 = nn.Linear(128, 10)

    def forward(self, x, y, z):
        x = F.relu(F.max_pool2d(self.conv1(x), 2))
        x = F.relu(F.max_pool2d(self.conv2(x), 2))
        x = x.view(-1, 1600)
        x = F.relu(self.fc1(x))
        x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        return F.log_softmax(x)


model = Network()
trainer = ModuleTrainer(model)

trainer.compile(loss='nll_loss', optimizer='adadelta')

trainer.fit([x_train, x_train, x_train],
            y_train,
            val_data=([x_test, x_test, x_test], y_test),
            num_epoch=3,
            batch_size=128,
            verbose=1)

ypred = trainer.predict([x_train, x_train, x_train])
print(ypred.size())

eval_loss = trainer.evaluate([x_train, x_train, x_train], y_train)
print(eval_loss)