Exemplo n.º 1
0
# coding: utf-8
import sys, os
sys.path.append(os.pardir)  # 親ディレクトリのファイルをインポートするための設定
import numpy as np
from dataset.cifar10 import load_cifar10
from PIL import Image

np.set_printoptions(threshold=100)

(x_train, t_train), (x_test, t_test) = load_cifar10(flatten=False)
x_test = x_test[:, :, :, ::-1]
padded = np.pad(x_test, ((0, 0), (0, 0), (4, 4), (0, 0)), mode='constant')
crops = np.random.randint(8, size=(len(x_test), 1))
x_test = np.array(
    [padded[i, :, c[0]:(c[0] + 32), :] for i, c in enumerate(crops)])

sample_image = x_test[0:100].reshape((10, 10, 3, 32, 32)).transpose(
    (0, 3, 1, 4, 2)).reshape((320, 320, 3))  # 先頭100個をタイル状に並べ替える
Image.fromarray(np.uint8(sample_image * 255)).save('sample.png')
print(t_test[0:100].reshape(10, 10))
#pil_img = Image.fromarray(np.uint8(sample_image*255))
#pil_img.show()
Exemplo n.º 2
0
# coding: utf-8
import sys, os
sys.path.append(os.pardir)  # 親ディレクトリのファイルをインポートするための設定
import pickle
import time
import cupy as cp
#import numpy as cp
import numpy as np
import matplotlib.pyplot as plt
from dataset.cifar10 import load_cifar10
from simple_convnet import SimpleConvNet
from common.trainer import Trainer

# データの読み込み
(x_train, t_train), (x_test, t_test) = load_cifar10(normalize=False, flatten=False, one_hot_label=True)

x_train = x_train * 2.0 - 255
x_test = x_test * 2.0 - 255

if os.path.exists("ttarray.pkl"):
    with open("ttarray.pkl", 'rb') as f:
        t_train = pickle.load(f)
        print("Loaded Teacher array!")

# 処理に時間のかかる場合はデータを削減 
#train_mask = np.random.choice(x_train.shape[0], 3000)
#x_train = x_train[train_mask]
#t_train = t_train[train_mask]

max_epochs = 25
Exemplo n.º 3
0
# coding: utf-8
import sys, os
sys.path.append(os.pardir)  # 親ディレクトリのファイルをインポートするための設定
import pickle
from common.np import *  # import numpy as np
from common.config import GPU
from dataset.cifar10 import load_cifar10
from slim_convnet import ConvNet
from common.functions import *

# データの読み込み
(x_train, t_train), (x_test, t_test) = load_cifar10(normalize=False,
                                                    flatten=False)

#x_train = x_train[:1000]
#t_train = t_train[:1000]

x_train = x_train * 2.0 - 255
x_test = x_test * 2.0 - 255

batch_size = 100

network = ConvNet(input_dim=(3, 32, 32), weight_init_std=0.01)

# パラメータの復帰
network.load_params("params.pkl")
print("Loaded Network Parameters!")

tt_array = np.empty((0, 10), np.float32)

for i in range(int(x_train.shape[0] / batch_size)):