def __getitem__(self, idx):
     img_root = self.data_list[idx]
     visit_array = visit_transform(img_root,self.args)
     name = img_root.split('/')[-1]
     label = int(img_root.split('/')[-2]) -1
     img = cv2.imread(img_root)
     if self.phase == 'train' and self.args.data_augmentation:
         img = augmentation(img)
     img = img / 255.0
     img= np.transpose(img,(2,0,1))
     return np.array(img), np.array(visit_array), label, name
Beispiel #2
0
def TakeOnePatch(image, label, patch_size):
    """
    image,label: take patch from these image and label
    patch_size: a int number, patch size is (patch_size,patch_size,patch_size) by default
    return: corresponding image_patch and label_patch 
    """

    image_data = image.get_data()
    label_data = label.get_data()

    x, y, z = label_data.shape

    i = np.random.randint(0, x - patch_size)
    j = np.random.randint(0, y - patch_size)
    k = np.random.randint(0, z - patch_size)

    image_cube_data = image_data[i:i + patch_size, j:j + patch_size,
                                 k:k + patch_size]
    label_cube_data = label_data[i:i + patch_size, j:j + patch_size,
                                 k:k + patch_size]

    image_patch, label_patch = augmentation(image_cube_data, label_cube_data)

    return image_patch, label_patch
import numpy as np
from models import Basic_Model, Hid_Model, Conv_Model, Conv_Model2, Conv_Model_WDDOBN, Conv_Model2_WDDOBN, Res_Model
from functions import *
from data_augmentation import augmentation
from fashion_mnist import load_fashion_mnist
import pickle

(x_train, y_train), (x_test, y_test) = load_fashion_mnist(normalize=True, flatten=False, one_hot_label=True)
x_train, y_train = augmentation(x_train, y_train, hflip=True, vflip=False)

model = Basic_Model()
#model = pickle.load(open("result/201905111739/model.pkl", 'rb'))

model.fit(x_train, y_train, x_test, y_test)

model.save_all()
Beispiel #4
0
from np import *
from config import GPU
from models import Basic_Model, Hid_Model, Conv_Model, Conv_Model2, Conv_Model32, Conv_Model_WDDOBN, Conv_Model2_WDDOBN, Res_Model, W_Res_Model
from functions import *
from fashion_mnist import load_fashion_mnist
import pickle
from data_augmentation import augmentation

(x_train, y_train), (x_test, y_test) = load_fashion_mnist(normalize=True,
                                                          flatten=False,
                                                          one_hot_label=True)

if GPU:
    x_train, x_test = to_gpu(x_train), to_gpu(x_test)
    y_train, y_test = to_gpu(y_train), to_gpu(y_test)
x_train, y_train = augmentation(x_train,
                                y_train,
                                hflip=False,
                                vflip=False,
                                hshift=True,
                                vshift=True)

model = Conv_Model32()
#model = pickle.load(open("result/201905111739/model.pkl", 'rb'))

model.fit(x_train, y_train, x_test, y_test)

model.save_all()
Beispiel #5
0
    if original_img is None:
        print('Input image error')
        print(common_params.images_dir + '/train/rgb/' + fname + '.png')
        sys.exit(1)

    # 画像をSSDの入力サイズにリサイズ
    original_img = cv.resize(original_img, (common_params.insize, common_params.insize), interpolation = cv.INTER_CUBIC)

    for ag in range(0, common_params.augmentation_factor):

        input_img = original_img.copy()
        idx = original_idx #クラス
        gt_boxes = original_gt_boxes

        if (ag >= 1):
            input_img, idx, gt_boxes, border_pixels, crop_param, hsv_param, flip_type = augmentation(input_img, idx, gt_boxes)

        if visible:
            out2 = input_img.copy()
            for bx in range(0, len(gt_boxes)):
                p1 = int(gt_boxes[bx][0])
                p2 = int(gt_boxes[bx][1])
                p3 = int(gt_boxes[bx][2])
                p4 = int(gt_boxes[bx][3])
                cv.rectangle(out2, (p1, p2), (p3, p4), (0, 255, 0), 2)

            cv.imshow('Augmentation', out2)
            cv.waitKey(10)

        img_width = input_img.shape[1]
        img_height = input_img.shape[0]