예제 #1
0
                        "beta1": beta1,
                    })

data_dir = './../../mxnet/example/image-classification/cifar10/'
train = mx.io.ImageRecordIter(path_imgrec=data_dir + "train.rec",
                              data_shape=data_shape[1:],
                              batch_size=batch_size,
                              shuffle=True)

metric_acc = mx.metric.CustomMetric(ferr)

for epoch in range(num_epoch):
    train.reset()
    metric_acc.reset()
    for t, batch in enumerate(train):
        batch.data[0] = batch.data[0] * (1.0 / 255.0) - 0.5
        gmod.update(batch)
        gmod.temp_label[:] = 0.0
        metric_acc.update([gmod.temp_label], gmod.outputs_fake)
        gmod.temp_label[:] = 1.0
        metric_acc.update([gmod.temp_label], gmod.outputs_real)

        if t % 50 == 0:
            logging.info("epoch: %d, iter %d, metric=%s", epoch, t,
                         metric_acc.get())
            viz.imshow("gout", gmod.temp_outG[0].asnumpy() + 0.5, 2, flip=True)
            diff = gmod.temp_diffD[0].asnumpy()
            diff = (diff - diff.mean()) / diff.std() + 0.5
            viz.imshow("diff", diff, flip=True)
            viz.imshow("data", batch.data[0].asnumpy() + 0.5, 2, flip=True)
                    })

data_dir = './../../mxnet/example/image-classification/mnist/'
train = mx.io.MNISTIter(image=data_dir + "train-images-idx3-ubyte",
                        label=data_dir + "train-labels-idx1-ubyte",
                        input_shape=data_shape[1:],
                        batch_size=batch_size,
                        shuffle=True)

metric_acc = mx.metric.CustomMetric(ferr)

for epoch in range(num_epoch):
    train.reset()
    metric_acc.reset()
    for t, batch in enumerate(train):
        gmod.update(batch)
        gmod.temp_label[:] = 0.0
        metric_acc.update([gmod.temp_label], gmod.outputs_fake)
        gmod.temp_label[:] = 1.0
        metric_acc.update([gmod.temp_label], gmod.outputs_real)

        if t % 100 == 0:
            logging.info("epoch: %d, iter %d, metric=%s", epoch, t,
                         metric_acc.get())
            continue
            viz.imshow("gout", gmod.temp_outG[0].asnumpy(), 2)
            diff = gmod.temp_diffD[0].asnumpy()
            diff = (diff - diff.mean()) / diff.std() + 0.5
            viz.imshow("diff", diff)
            viz.imshow("data", batch.data[0].asnumpy(), 2)
        "beta1": beta1,
})

data_dir = './../../mxnet/example/image-classification/cifar10/'
train = mx.io.ImageRecordIter(
    path_imgrec = data_dir + "train.rec",
    data_shape = data_shape[1:],
    batch_size = batch_size,
    shuffle=True)

metric_acc = mx.metric.CustomMetric(ferr)

for epoch in range(num_epoch):
    train.reset()
    metric_acc.reset()
    for t, batch in enumerate(train):
        batch.data[0] = batch.data[0] * (1.0 / 255.0) - 0.5
        gmod.update(batch, is_labeled=True)
        gmod.temp_label[:] = 0.0
        metric_acc.update([gmod.temp_label], gmod.outputs_fake)
        gmod.temp_label[:] = 1.0
        metric_acc.update([gmod.temp_label], gmod.outputs_real)

        if t % 50 == 0:
            logging.info("epoch: %d, iter %d, metric=%s", epoch, t, metric_acc.get())
            viz.imshow("gout", gmod.temp_outG[0].asnumpy() + 0.5 , 2, flip=True)
            diff = gmod.temp_diffD[0].asnumpy()
            diff = (diff - diff.mean()) / diff.std() + 0.5
            viz.imshow("diff", diff, flip=True)
            viz.imshow("data", batch.data[0].asnumpy() + 0.5, 2, flip=True)
})

data_dir = './../../mxnet/example/image-classification/mnist/'
train = mx.io.MNISTIter(
    image = data_dir + "train-images-idx3-ubyte",
    label = data_dir + "train-labels-idx1-ubyte",
    input_shape = data_shape[1:],
    batch_size = batch_size,
    shuffle = True)

metric_acc = mx.metric.CustomMetric(ferr)

for epoch in range(num_epoch):
    train.reset()
    metric_acc.reset()
    for t, batch in enumerate(train):
        gmod.update(batch)
        gmod.temp_label[:] = 0.0
        metric_acc.update([gmod.temp_label], gmod.outputs_fake)
        gmod.temp_label[:] = 1.0
        metric_acc.update([gmod.temp_label], gmod.outputs_real)

        if t % 100 == 0:
            logging.info("epoch: %d, iter %d, metric=%s", epoch, t, metric_acc.get())
            continue
            viz.imshow("gout", gmod.temp_outG[0].asnumpy(), 2)
            diff = gmod.temp_diffD[0].asnumpy()
            diff = (diff - diff.mean()) / diff.std() + 0.5
            viz.imshow("diff", diff)
            viz.imshow("data", batch.data[0].asnumpy(), 2)
예제 #5
0
data_dir = '/Users/tornadomeet/project/dmlc/mxNet/example/image-classification/data/'
train = mx.io.MNISTIter(
    image = data_dir + "train-images-idx3-ubyte",
    label = data_dir + "train-labels-idx1-ubyte",
    input_shape = data_shape[1:],
    batch_size = batch_size,
    shuffle = True)

metric_acc = mx.metric.CustomMetric(ferr)

for epoch in range(num_epoch):
    train.reset()
    metric_acc.reset()
    for t, batch in enumerate(train):
        gmod.update(batch)
        gmod.temp_label[:] = 0.0
        metric_acc.update([gmod.temp_label], gmod.outputs_fake)
        gmod.temp_label[:] = 1.0
        metric_acc.update([gmod.temp_label], gmod.outputs_real)

        if t % 100 == 0:
            logging.info("epoch: %d, iter %d, metric=%s", epoch, t, metric_acc.get())
            gdata = gmod.temp_outG[0].asnumpy()
            viz.imshow("gout", gdata, 2)
            diff = gmod.temp_diffD[0].asnumpy()
            diff = (diff - diff.mean()) / diff.std() + 0.5
            viz.imshow("diff", diff)
            viz.imshow("data", batch.data[0].asnumpy(), 2)
            if epoch == num_epoch -1:
                cv2.imsave("epcho-{}-iter-{}".format(epoch, t), gdata)