def __init__(self, resolution=None, input_shape=None): super(Flower_DataSet, self).__init__() if resolution is None: resolution = [100, 100] if input_shape is None: input_shape = [-1] path = '../data/flowers' self.target_names = mu.list_dir(path) images = [] idxs = [] for dx, dname in enumerate(self.target_names): subpath = path + '/' + dname filenames = mu.list_dir(subpath) for fname in filenames: if fname[-4:] != '.jpg': continue imagepath = os.path.join(subpath, fname) pixels = mu.load_image_pixels(imagepath, resolution, input_shape) images.append(pixels) idxs.append(dx) self.image_shape = resolution + [3] xs = np.asarray(images, np.float32) ys = mu.onehot(idxs, len(self.target_names)) self.dataset_shuffle_data(xs, ys, 0.8)
def __init__(self, resolution=None, input_shape=None): super(Office31Dataset, self).__init__() if resolution is None: resolution = [100, 100] if input_shape is None: input_shape = [-1] path = '../data/domain_adaptation_images' domain_names = mu.list_dir(path) images = [] didxs, oidxs = [], [] object_names = None for dx, dname in enumerate(domain_names): domainpath = os.path.join(path, dname, 'images') object_names = mu.list_dir(domainpath) for ox, oname in enumerate(object_names): objectpath = os.path.join(domainpath, oname) filenames = mu.list_dir(objectpath) for fname in filenames: if fname[-4:] != '.jpg': continue imagepath = os.path.join(objectpath, fname) pixels = mu.load_image_pixels(imagepath, resolution, input_shape) images.append(pixels) didxs.append(dx) oidxs.append(ox) self.image_shape = resolution + [3] xs = np.asarray(images, np.float32) # shape(4110, 30000) ys0 = mu.onehot(didxs, len(domain_names)) # ys0.shape(4110, 3) ys1 = mu.onehot(oidxs, len(object_names)) # ys1.shape(4110, 31) ys = np.hstack([ys0, ys1]) # ys.shape(4110, 34) self.dataset_shuffle_data(xs, ys, 0.8) self.target_names = [domain_names, object_names] self.cnts = [len(domain_names)]
def __init__(self, name): super(DataSet, self).__init__(name) # print("dataset init") resolution = [100, 100] input_shape = [-1] self.initialize() if self.name == 'abalone': elif self.name == 'pulsar': rows, _ = mu.load_csv('../data/pulsar_stars.csv') data = np.asarray(rows, dtype='float32') self.dataset_shuffle_data(data[:, :-1], data[:, -1:], 0.8) self.target_names = ['별', '펄서'] elif self.name == 'steel': rows, headers = mu.load_csv('../data/faults.csv') data = np.asarray(rows, dtype='float32') self.dataset_shuffle_data(data[:, :-7], data[:, -7:], 0.8) self.target_names = headers[-7:] elif self.name == 'pulsarselect': rows, _ = mu.load_csv('../data/pulsar_stars.csv') data = np.asarray(rows, dtype='float32') self.dataset_shuffle_data(data[:, :-1], mu.onehot(data[:, -1], 2), 0.8) self.target_names = ['별', '펄서'] elif self.name == 'flower': path = '../data/flowers' self.target_names = mu.list_dir(path) images = [] idxs = [] for dx, dname in enumerate(self.target_names): subpath = path + '/' + dname filenames = mu.list_dir(subpath) for fname in filenames: if fname[-4:] != '.jpg': continue imagepath = os.path.join(subpath, fname) pixels = mu.load_image_pixels(imagepath, resolution, input_shape) images.append(pixels) idxs.append(dx) self.image_shape = resolution + [3] xs = np.asarray(images, np.float32) ys = mu.onehot(idxs, len(self.target_names)) self.dataset_shuffle_data(xs, ys, 0.8) elif self.name == 'office31': path = '../data/domain_adaptation_images' domain_names = mu.list_dir(path) images = [] didxs, oidxs = [], [] object_names = None for dx, dname in enumerate(domain_names): domainpath = os.path.join(path, dname, 'images') object_names = mu.list_dir(domainpath) for ox, oname in enumerate(object_names): objectpath = os.path.join(domainpath, oname) filenames = mu.list_dir(objectpath) for fname in filenames: if fname[-4:] != '.jpg': continue imagepath = os.path.join(objectpath, fname) pixels = mu.load_image_pixels(imagepath, resolution, input_shape) images.append(pixels) didxs.append(dx) oidxs.append(ox) self.image_shape = resolution + [3] xs = np.asarray(images, np.float32) # shape(4110, 30000) ys0 = mu.onehot(didxs, len(domain_names)) # ys0.shape(4110, 3) ys1 = mu.onehot(oidxs, len(object_names)) # ys1.shape(4110, 31) ys = np.hstack([ys0, ys1]) # ys.shape(4110, 34) self.dataset_shuffle_data(xs, ys, 0.8) self.target_names = [domain_names, object_names] print(type(self.target_names[0])) self.cnts = [len(domain_names)]
def __init__(self): super(Pulsar_Select_DataSet, self).__init__() rows, _ = mu.load_csv('../data/pulsar_stars.csv') data = np.asarray(rows, dtype='float32') self.dataset_shuffle_data(data[:, :-1], mu.onehot(data[:, -1], 2), 0.8) self.target_names = ['별', '펄서']