Beispiel #1
0
def showDataSet(dataMat, labelMat):
    data_plus = []
    for i in range(len(group)):
        data_plus.append(dataMat[i])
    data_plus_np = np.array(data_plus)  # 转换为numpy矩阵
    plt.scatter(np.transpose(data_plus_np)[0],
                np.transpose(data_plus_np)[1])  # 散点图
    plt.show()
Beispiel #2
0
def get_hist(data, col):
    [columndates, orderdates] = column_and_order_dates(data, col)
    [difference_dates, date_values] = days_difference(columndates, orderdates,
                                                      31)

    plt.hist(x=difference_dates, bins=100)
    plt.xlabel('Day')
    plt.ylabel('Amount')
    plt.show()
    print(date_values)
Beispiel #3
0
def show_images(images, labels, preds):
    plt.figure(figsize=(8, 4))
    for i, image in enumerate(images):
        plt.subplot(1, 6, i + 1, xticks=[], yticks=[])
        image = image.numpy().transpose((1, 2, 0))
        mean = np.array([0.485, 0.456, 0.406])
        std = np.array([0.229, 0.224, 0.225])
        image = image * std + mean
        image = np.clip(image, 0., 1.)
        plt.imshow(image)
        col = 'green'
        if preds[i] != labels[i]:
            col = 'red'

        plt.xlabel(f'{class_names[int(labels[i].numpy())]}')
        plt.ylabel(f'{class_names[int(preds[i].numpy())]}', color=col)
    plt.tight_layout()
    plt.show()
Beispiel #4
0
    if torch.cuda.is_available():
        model.cuda()
    for epoch in range(epoches):  #循环epoch,设置学习率
        if epoch in [epoches * 0.25, epoches * 0.5]:
            for param_group in optimizier.param_groups:
                param_group['lr'] *= 0.1
        for img, _ in train_data:
            img = img.view(img.size(0), -1)
            img = Variable(img.cuda())
            #forward
            _, output = model(img)  #把数据放入模型
            loss = criterion(output, img)  #损失
            #backward
            optimizier.zero_grad()
            loss.backward()
            optimizier.step()
        print('epoch=', epoch, loss.data.float())
        for param_group in optimizier.param_groups:
            print(param_group['lr'])
        if (epoch + 1) % 5 == 0:
            pic = to_img(output.cpu().data)
            if not os.path.exists('./simple_autoencoder'):  #判断该路径是否存在
                os.mkdir(pic, './simple_autoencoder/image_{}.png'.format(
                    epoch + 1))  #如果不存在则将处理后的数据放入该路径
    code = Variable(torch.FloatTensor([1.19, -3.36, 2.06]).cuda())
    decode = model.decoder(code)  #解码
    decode_img = to_img(decode).squeeze()
    decode_img = decode_img.data.cpu().numpy() * 255
    plt.imshow(decode_img.astype('uint8'), cmap='gray')
    plt.show()