예제 #1
0
                              i * batch_number + j)
            # PARAMS
            for name, param in net.named_parameters():
                writer.add_histogram(name,
                                     param.clone().cpu().data.numpy(),
                                     i * batch_number + j)

        if j % logging_text_step == 0:
            net.train(False)
            # STEP
            s = "non sopporto i giocatori di biliardo, i soprannomi, gli indecisi, i no"[
                0:75]
            s_final = s
            s = numpy.asarray([
                CHARS.index(c) if c in CHARS else CHARS.index(FILL_CHAR)
                for c in s
            ])
            s = to_categorical(s, num_classes=features_size)
            for k in xrange(500):
                c = net(
                    Variable(torch.FloatTensor(
                        s[numpy.newaxis, ...])).cuda()).cpu().data.numpy()
                c = numpy.where(c < numpy.max(c), 0, 1)
                s = numpy.append(s, c, 0)
                s = s[1:]
                c = numpy.argmax(c, 1)[0]
                s_final += CHARS[c]

            writer.add_text("text_sample", s_final, i * batch_number + j)
    progress.finish()
예제 #2
0
                    default=1,
                    help='number of GPUs to use')
parser.add_argument('--netG',
                    default='',
                    help="path to netG (to continue training)")
parser.add_argument('--netD',
                    default='',
                    help="path to netD (to continue training)")
parser.add_argument('--outf',
                    default='.',
                    help='folder to output images and model checkpoints')
parser.add_argument('--manualSeed', type=int, help='manual seed')

opt = parser.parse_args()
print(opt)
writer.add_text('opt', str(opt), 0)
try:
    os.makedirs(opt.outf)
except OSError:
    pass

if opt.manualSeed is None:
    opt.manualSeed = random.randint(1, 10000)
print("Random Seed: ", opt.manualSeed)
writer.add_text('Random Seed: ', str(opt.manualSeed), 0)
random.seed(opt.manualSeed)
torch.manual_seed(opt.manualSeed)
if opt.cuda:
    torch.cuda.manual_seed_all(opt.manualSeed)

cudnn.benchmark = True
예제 #3
0
import torch
import torchvision.utils as vutils
import numpy as np
import torchvision.models as models
from datetime import datetime
from tensorboard import SummaryWriter
resnet18 = models.resnet18(True)
writer = SummaryWriter('runs/' + datetime.now().strftime('%B%d  %H:%M:%S'))
sample_rate = 44100
freqs = [262, 294, 330, 349, 392, 440, 440, 440, 440, 440, 440]
for n_iter in range(100):
    M_global = torch.rand(1)  # value to keep
    writer.add_scalar('M_global', M_global[0], n_iter)
    x = torch.rand(32, 3, 64, 64)  # output from network
    if n_iter % 10 == 0:
        x = vutils.make_grid(x, normalize=True, scale_each=True)
        writer.add_image('Image', x, n_iter)
        x = torch.zeros(sample_rate * 2)
        for i in range(x.size(0)):
            x[i] = np.cos(
                freqs[n_iter // 10] * np.pi * float(i) /
                float(sample_rate))  # sound amplitude should in [-1, 1]
        writer.add_audio('Audio', x, n_iter)
        for name, param in resnet18.named_parameters():
            writer.add_histogram(name,
                                 param.clone().cpu().data.numpy(), n_iter)
        writer.add_text('Text', 'text logged at step:' + str(n_iter), n_iter)
        writer.add_text('another Text',
                        'another text logged at step:' + str(n_iter), n_iter)

writer.close()
    # Fix the number of epochs to train for
    n_epochs = 10

    threshold = 0.01 * 10 ** (-21)

    # -------------------------------------------------------------------------
    # SET UP A LOGGER FOR TENSORBOARD VISUALIZATION
    # -------------------------------------------------------------------------

    run_start = datetime.datetime.now()
    log_name = [run_start, distances, sample_size, initial_lr, threshold]
    log_name_formatted = '[{:%Y-%m-%d_%H:%M}]-[{}]-[{}]-[lr_{:.1e}]-'\
                         '[thresh_{:.2e}]'.format(*log_name)
    writer = SummaryWriter(log_dir='logs/{}'.format(log_name_formatted))
    writer.add_text(tag='Description',
                    text_string='(Description missing.)')

    # -------------------------------------------------------------------------
    # TRAIN THE NET FOR THE GIVEN NUMBER OF EPOCHS
    # -------------------------------------------------------------------------

    print('\nStart training: Training on {} examples, validating on {} '
          'examples\n'.format(len(data_train), len(data_validation)))

    # -------------------------------------------------------------------------

    for epoch in range(n_epochs):

        print('Epoch {}/{}'.format(epoch+1, n_epochs))

        running_loss = 0
    metrics = {'loss': [], 'hamming': [], 'val_loss': [], 'val_hamming': []}

    # -------------------------------------------------------------------------
    # SET UP A LOGGER FOR TENSORBOARD VISUALIZATION
    # -------------------------------------------------------------------------

    # Define a log directory and set up a writer
    run_start = datetime.datetime.now()
    log_name = [
        run_start, noise_source, distances, sample_size, initial_lr, threshold,
        regularization_parameter
    ]
    log_name_formatted = '[{:%Y-%m-%d_%H:%M}]-[{}]-[{}]-[{}]-[LR_{:.1e}]-'\
                         '[THR_{:.1f}]_[REG_{:.2e}]'.format(*log_name)
    writer = SummaryWriter(log_dir='logs/{}'.format(log_name_formatted))
    writer.add_text(tag='Description', text_string=description)

    # Define a shortcut to write metrics to the log
    def log_metric(name, value, epoch):
        writer.add_scalar(name, value, epoch)

    # -------------------------------------------------------------------------
    # TRAIN THE NET FOR THE GIVEN NUMBER OF EPOCHS
    # -------------------------------------------------------------------------

    print('\nStart training: Training on {} examples, validating on {} '
          'examples\n'.format(len(data_train), len(data_validation)))

    # -------------------------------------------------------------------------
    #