Пример #1
0
    optimizer = torch.optim.Adam(net.parameters(),
                                 eps=0.000001,
                                 lr=args.lr,
                                 betas=(0.9, 0.999),
                                 weight_decay=0.0001)

    # training loop
    for epoch in range(1, args.epochs):
        accuracy = train(net, train_loader, optimizer)
        if epoch % 100 == 0 and accuracy == 100:
            break

# graph hidden units
for layer in [1, 2]:
    if layer == 1 or args.net != 'polar':
        for node in range(args.hid):
            graph_hidden(net, layer, node)
            plt.scatter(full_input[:, 0],
                        full_input[:, 1],
                        c=1 - full_target[:, 0],
                        cmap='RdYlBu')
            plt.savefig('%s%d_%d.png' % (args.net, layer, node))

# graph output unit
graph_output(net)
plt.scatter(full_input[:, 0],
            full_input[:, 1],
            c=1 - full_target[:, 0],
            cmap='RdYlBu')
plt.savefig('%s_out.png' % args.net)
Пример #2
0
    optimizer = torch.optim.Adam(net.parameters(),
                                 eps=0.000001,
                                 lr=args.lr,
                                 betas=(0.9, 0.999),
                                 weight_decay=0.0001)
    # optimizer = torch.optim.SGD(net.parameters(), lr=args.lr, weight_decay=0.0001)

    for epoch in range(1, args.epochs):
        accuracy = train(net, train_loader, optimizer)
        if epoch % 100 == 0 and accuracy == 100:
            break

# save model
for layer in [1, 2]:
    if layer == 1 or args.net != 'polar':
        for node in range(args.hid):
            graph_hidden(net, layer, node)  # output hiden layer values
            plt.scatter(full_input[:, 0],
                        full_input[:, 1],
                        c=1 - full_target[:, 0],
                        cmap='RdYlBu')
            plt.savefig('%s%d_%d.png' % (args.net, layer, node))

graph_output(net)
plt.scatter(full_input[:, 0],
            full_input[:, 1],
            c=1 - full_target[:, 0],
            cmap='RdYlBu')
plt.savefig('%s_out.png' % args.net)