Python numpy.flip() Examples
The following are 30 code examples for showing how to use numpy.flip(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: scanorama Author: brianhie File: time_align.py License: MIT License | 7 votes |
def time_align_visualize(alignments, time, y, namespace='time_align'): plt.figure() heat = np.flip(alignments + alignments.T + np.eye(alignments.shape[0]), axis=0) sns.heatmap(heat, cmap="YlGnBu", vmin=0, vmax=1) plt.savefig(namespace + '_heatmap.svg') G = nx.from_numpy_matrix(alignments) G = nx.maximum_spanning_tree(G) pos = {} for i in range(len(G.nodes)): pos[i] = np.array([time[i], y[i]]) mst_edges = set(nx.maximum_spanning_tree(G).edges()) weights = [ G[u][v]['weight'] if (not (u, v) in mst_edges) else 8 for u, v in G.edges() ] plt.figure() nx.draw(G, pos, edges=G.edges(), width=10) plt.ylim([-1, 1]) plt.savefig(namespace + '.svg')
Example 2
Project: tf2-yolo3 Author: akkaze File: utils.py License: Apache License 2.0 | 7 votes |
def draw_outputs(img, outputs, class_names=None): boxes, objectness, classes = outputs #boxes, objectness, classes = boxes[0], objectness[0], classes[0] wh = np.flip(img.shape[0:2]) if img.ndim == 2 or img.shape[2] == 1: img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) min_wh = np.amin(wh) if min_wh <= 100: font_size = 0.5 else: font_size = 1 for i in range(classes.shape[0]): x1y1 = tuple((np.array(boxes[i][0:2]) * wh).astype(np.int32)) x2y2 = tuple((np.array(boxes[i][2:4]) * wh).astype(np.int32)) img = cv2.rectangle(img, x1y1, x2y2, (255, 0, 0), 1) img = cv2.putText(img, '{}'.format(int(classes[i])), x1y1, cv2.FONT_HERSHEY_COMPLEX_SMALL, font_size, (0, 0, 255), 1) return img
Example 3
Project: tf2-yolo3 Author: akkaze File: utils.py License: Apache License 2.0 | 7 votes |
def draw_labels(x, y, class_names=None): img = x.numpy() if img.ndim == 2 or img.shape[2] == 1: img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) boxes, classes = tf.split(y, (4, 1), axis=-1) classes = classes[..., 0] wh = np.flip(img.shape[0:2]) min_wh = np.amin(wh) if min_wh <= 100: font_size = 0.5 else: font_size = 1 for i in range(len(boxes)): x1y1 = tuple((np.array(boxes[i][0:2]) * wh).astype(np.int32)) x2y2 = tuple((np.array(boxes[i][2:4]) * wh).astype(np.int32)) img = cv2.rectangle(img, x1y1, x2y2, (255, 0, 0), 1) if class_names: img = cv2.putText(img, class_names[classes[i]], x1y1, cv2.FONT_HERSHEY_COMPLEX_SMALL, font_size, (0, 0, 255), 1) else: img = cv2.putText(img, str(classes[i]), x1y1, cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1) return img
Example 4
Project: sparse-subspace-clustering-python Author: abhinav4192 File: BuildAdjacency.py License: MIT License | 6 votes |
def BuildAdjacency(CMat, K): CMat = CMat.astype(float) CKSym = None N, _ = CMat.shape CAbs = np.absolute(CMat).astype(float) for i in range(0, N): c = CAbs[:, i] PInd = np.flip(np.argsort(c), 0) CAbs[:, i] = CAbs[:, i] / float(np.absolute(c[PInd[0]])) CSym = np.add(CAbs, CAbs.T).astype(float) if K != 0: Ind = np.flip(np.argsort(CSym, axis=0), 0) CK = np.zeros([N, N]).astype(float) for i in range(0, N): for j in range(0, K): CK[Ind[j, i], i] = CSym[Ind[j, i], i] / float(np.absolute(CSym[Ind[0, i], i])) CKSym = np.add(CK, CK.T) else: CKSym = CSym return CKSym
Example 5
Project: py360convert Author: sunset1995 File: utils.py License: MIT License | 6 votes |
def equirect_facetype(h, w): ''' 0F 1R 2B 3L 4U 5D ''' tp = np.roll(np.arange(4).repeat(w // 4)[None, :].repeat(h, 0), 3 * w // 8, 1) # Prepare ceil mask mask = np.zeros((h, w // 4), np.bool) idx = np.linspace(-np.pi, np.pi, w // 4) / 4 idx = h // 2 - np.round(np.arctan(np.cos(idx)) * h / np.pi).astype(int) for i, j in enumerate(idx): mask[:j, i] = 1 mask = np.roll(np.concatenate([mask] * 4, 1), 3 * w // 8, 1) tp[mask] = 4 tp[np.flip(mask, 0)] = 5 return tp.astype(np.int32)
Example 6
Project: pymoo Author: msu-coinlab File: randomized_argsort.py License: Apache License 2.0 | 6 votes |
def randomized_argsort(A, method="numpy", order='ascending'): if method == "numpy": P = np.random.permutation(len(A)) I = np.argsort(A[P], kind='quicksort') I = P[I] elif method == "quicksort": I = quicksort(A) else: raise Exception("Randomized sort method not known.") if order == 'ascending': return I elif order == 'descending': return np.flip(I, axis=0) else: raise Exception("Unknown sorting order: ascending or descending.")
Example 7
Project: HorizonNet Author: sunset1995 File: inference.py License: MIT License | 6 votes |
def augment_undo(x_imgs_augmented, aug_type): x_imgs_augmented = x_imgs_augmented.cpu().numpy() sz = x_imgs_augmented.shape[0] // len(aug_type) x_imgs = [] for i, aug in enumerate(aug_type): x_img = x_imgs_augmented[i*sz : (i+1)*sz] if aug == 'flip': x_imgs.append(np.flip(x_img, axis=-1)) elif aug.startswith('rotate'): shift = int(aug.split()[-1]) x_imgs.append(np.roll(x_img, -shift, axis=-1)) elif aug == '': x_imgs.append(x_img) else: raise NotImplementedError() return np.array(x_imgs)
Example 8
Project: HorizonNet Author: sunset1995 File: dataset.py License: MIT License | 6 votes |
def __init__(self, root_dir, flip=False, rotate=False, gamma=False, stretch=False, p_base=0.96, max_stretch=2.0, normcor=False, return_cor=False, return_path=False): self.img_dir = os.path.join(root_dir, 'img') self.cor_dir = os.path.join(root_dir, 'label_cor') self.img_fnames = sorted([ fname for fname in os.listdir(self.img_dir) if fname.endswith('.jpg') or fname.endswith('.png') ]) self.txt_fnames = ['%s.txt' % fname[:-4] for fname in self.img_fnames] self.flip = flip self.rotate = rotate self.gamma = gamma self.stretch = stretch self.p_base = p_base self.max_stretch = max_stretch self.normcor = normcor self.return_cor = return_cor self.return_path = return_path self._check_dataset()
Example 9
Project: Keras-BiGAN Author: manicman1999 File: bigan.py License: MIT License | 6 votes |
def __init__(self, steps = 1, lr = 0.0001, decay = 0.00001, silent = True): self.GAN = GAN(steps = steps, lr = lr, decay = decay) self.DisModel = self.GAN.DisModel() self.AdModel = self.GAN.AdModel() self.lastblip = time.clock() self.noise_level = 0 self.im = dataGenerator(directory, suffix = suff, flip = True) self.silent = silent #Train Generator to be in the middle, not all the way at real. Apparently works better?? self.ones = np.ones((BATCH_SIZE, 1), dtype=np.float32) self.zeros = np.zeros((BATCH_SIZE, 1), dtype=np.float32) self.nones = -self.ones
Example 10
Project: recruit Author: Frank-qlu File: test_function_base.py License: Apache License 2.0 | 6 votes |
def test_multiple_axes(self): a = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) assert_equal(np.flip(a, axis=()), a) b = np.array([[[5, 4], [7, 6]], [[1, 0], [3, 2]]]) assert_equal(np.flip(a, axis=(0, 2)), b) c = np.array([[[3, 2], [1, 0]], [[7, 6], [5, 4]]]) assert_equal(np.flip(a, axis=(1, 2)), c)
Example 11
Project: tensornets Author: taehoonlee File: utils.py License: MIT License | 6 votes |
def crop(img, crop_size, crop_loc=4, crop_grid=(3, 3)): if isinstance(crop_loc, list): imgs = np.zeros((img.shape[0], len(crop_loc), crop_size, crop_size, 3), np.float32) for (i, loc) in enumerate(crop_loc): r, c = crop_idx(img.shape[1:3], crop_size, loc, crop_grid) imgs[:, i] = img[:, r:r+crop_size, c:c+crop_size, :] return imgs elif crop_loc == np.prod(crop_grid) + 1: imgs = np.zeros((img.shape[0], crop_loc, crop_size, crop_size, 3), np.float32) r, c = crop_idx(img.shape[1:3], crop_size, 4, crop_grid) imgs[:, 0] = img[:, r:r+crop_size, c:c+crop_size, :] imgs[:, 1] = img[:, 0:crop_size, 0:crop_size, :] imgs[:, 2] = img[:, 0:crop_size, -crop_size:, :] imgs[:, 3] = img[:, -crop_size:, 0:crop_size, :] imgs[:, 4] = img[:, -crop_size:, -crop_size:, :] imgs[:, 5:] = np.flip(imgs[:, :5], axis=3) return imgs else: r, c = crop_idx(img.shape[1:3], crop_size, crop_loc, crop_grid) return img[:, r:r+crop_size, c:c+crop_size, :]
Example 12
Project: mabalgs Author: alison-carrera File: algs.py License: Apache License 2.0 | 6 votes |
def select(self): """ This method selects the best arm chosen by Thompsom Sampling. :return: Return selected arm number. Arm number returned is (n_arm - 1). Returns a list of arms by importance. The chosen arm is the index 0 of this list. """ rewards_0 = self.n_impressions - self.n_rewards rewards_0[rewards_0 <= 0] = 1 theta_value = np.random.beta(self.n_rewards, rewards_0) ranked_arms = np.flip(np.argsort(theta_value), axis=0) chosen_arm = ranked_arms[0] self.n_impressions[chosen_arm] += 1 return chosen_arm, ranked_arms
Example 13
Project: StyleGAN2-Tensorflow-2.0 Author: manicman1999 File: datagen.py License: MIT License | 6 votes |
def __init__(self, folder, im_size, mss = (1024 ** 3), flip = True, verbose = True): self.folder = folder self.im_size = im_size self.segment_length = mss // (im_size * im_size * 3) self.flip = flip self.verbose = verbose self.segments = [] self.images = [] self.update = 0 if self.verbose: print("Importing images...") print("Maximum Segment Size: ", self.segment_length) try: os.mkdir("data/" + self.folder + "-npy-" + str(self.im_size)) except: self.load_from_npy(folder) return self.folder_to_npy(self.folder) self.load_from_npy(self.folder)
Example 14
Project: StyleGAN2-Tensorflow-2.0 Author: manicman1999 File: datagen.py License: MIT License | 6 votes |
def get_batch(self, num): if self.update > self.images.shape[0]: self.load_from_npy(self.folder) self.update = self.update + num idx = np.random.randint(0, self.images.shape[0] - 1, num) out = [] for i in idx: out.append(self.images[i]) if self.flip and random.random() < 0.5: out[-1] = np.flip(out[-1], 1) return np.array(out).astype('float32') / 255.0
Example 15
Project: signaltrain Author: drscotthawley File: viz.py License: GNU General Public License v3.0 | 6 votes |
def show_2d(array_2d, title="weights_layer", colormap=rainbow, flip=True): #print("weights_layer.shape = ",weights_layer.shape) if len(array_2d.shape) < 2: return img = np.clip(array_2d*255 ,-255,255).astype(np.uint8) # scale if flip: img = np.flip(np.transpose(img)) img = np.repeat(img[:,:,np.newaxis],3,axis=2) # add color channels img = cv2.applyColorMap(img, colormap) # rainbow: blue=low, red=high # see if it exists new_window = not check_window_exists(title) window = cv2.namedWindow(title,cv2.WINDOW_NORMAL) cv2.imshow(title, img) if new_window: cv2.resizeWindow(title, img.shape[1], img.shape[0]) # show what we've got #aspect = img.shape[0] / img.shape[1] #if aspect > 3: # cv2.resizeWindow(title, 200, 1024) # zoom in/out (can use two-finger-scroll to zoom in) #print(f"size for {title} = 1024, {int(1024/aspect*img.shape[0])}") #else: # cv2.resizeWindow(title, int(imWidth/2),int(imWidth/2)) # zoom in/out (can use two-finger-scroll to zoom in) # draw weights for all layers using model state dict
Example 16
Project: neuropythy Author: noahbenson File: core.py License: GNU Affero General Public License v3.0 | 5 votes |
def reverse(self): ''' curve.reverse() yields the inverted spline-curve equivalent to curve. ''' return CurveSpline( np.flip(self.coordinates, axis=1), distances=(None if self.distances is None else np.flip(self.distances, axis=0)), order=self.order, weights=self.weights, smoothing=self.smoothing, periodic=self.periodic, meta_data=self.meta_data)
Example 17
Project: neural-combinatorial-optimization-rl-tensorflow Author: MichelDeudon File: dataset.py License: MIT License | 5 votes |
def swap2opt(tsptw_sequence,i,j): new_tsptw_sequence = np.copy(tsptw_sequence) new_tsptw_sequence[i:j+1] = np.flip(tsptw_sequence[i:j+1], axis=0) # flip or swap ? return new_tsptw_sequence # One step of 2opt = one double loop and return first improved sequence
Example 18
Project: graph-neural-networks Author: alelab-upenn File: graphTools.py License: GNU General Public License v3.0 | 5 votes |
def permDegree(S): """ permDegree: determines the permutation by degree (nodes ordered from highest degree to lowest) Input: S (np.array): matrix Output: permS (np.array): matrix permuted order (list): list of indices to permute S to turn into permS. """ assert len(S.shape) == 2 or len(S.shape) == 3 if len(S.shape) == 2: assert S.shape[0] == S.shape[1] S = S.reshape([1, S.shape[0], S.shape[1]]) scalarWeights = True else: assert S.shape[1] == S.shape[2] scalarWeights = False # Compute the degree d = np.sum(np.sum(S, axis = 1), axis = 0) # Sort ascending order (from min degree to max degree) order = np.argsort(d) # Reverse sorting order = np.flip(order,0) # And update S S = S[:,order,:][:,:,order] # If the original GSO assumed scalar weights, get rid of the extra dimension if scalarWeights: S = S.reshape([S.shape[1], S.shape[2]]) return S, order.tolist()
Example 19
Project: pytorch-mri-segmentation-3D Author: Achilleas File: augmentations.py License: MIT License | 5 votes |
def applyFLIPS(images, flip_lvl = 0): if flip_lvl == 0: p = np.random.rand(2) > 0.5 else: p = np.random.rand(3) > 0.5 locations = np.where(p == 1)[0] + 2 new_imgs = [] for img in images: for i in locations: img = np.flip(img, axis=i) new_imgs.append(img) return new_imgs
Example 20
Project: pytorch-mri-segmentation-3D Author: Achilleas File: augmentations.py License: MIT License | 5 votes |
def applyFLIPS2(images, locations): new_imgs = [] for img in images: for i in locations: img = np.flip(img, axis=i) new_imgs.append(img) return new_imgs
Example 21
Project: py360convert Author: sunset1995 File: utils.py License: MIT License | 5 votes |
def sample_cubefaces(cube_faces, tp, coor_y, coor_x, order): cube_faces = cube_faces.copy() cube_faces[1] = np.flip(cube_faces[1], 1) cube_faces[2] = np.flip(cube_faces[2], 1) cube_faces[4] = np.flip(cube_faces[4], 0) # Pad up down pad_ud = np.zeros((6, 2, cube_faces.shape[2])) pad_ud[0, 0] = cube_faces[5, 0, :] pad_ud[0, 1] = cube_faces[4, -1, :] pad_ud[1, 0] = cube_faces[5, :, -1] pad_ud[1, 1] = cube_faces[4, ::-1, -1] pad_ud[2, 0] = cube_faces[5, -1, ::-1] pad_ud[2, 1] = cube_faces[4, 0, ::-1] pad_ud[3, 0] = cube_faces[5, ::-1, 0] pad_ud[3, 1] = cube_faces[4, :, 0] pad_ud[4, 0] = cube_faces[0, 0, :] pad_ud[4, 1] = cube_faces[2, 0, ::-1] pad_ud[5, 0] = cube_faces[2, -1, ::-1] pad_ud[5, 1] = cube_faces[0, -1, :] cube_faces = np.concatenate([cube_faces, pad_ud], 1) # Pad left right pad_lr = np.zeros((6, cube_faces.shape[1], 2)) pad_lr[0, :, 0] = cube_faces[1, :, 0] pad_lr[0, :, 1] = cube_faces[3, :, -1] pad_lr[1, :, 0] = cube_faces[2, :, 0] pad_lr[1, :, 1] = cube_faces[0, :, -1] pad_lr[2, :, 0] = cube_faces[3, :, 0] pad_lr[2, :, 1] = cube_faces[1, :, -1] pad_lr[3, :, 0] = cube_faces[0, :, 0] pad_lr[3, :, 1] = cube_faces[2, :, -1] pad_lr[4, 1:-1, 0] = cube_faces[1, 0, ::-1] pad_lr[4, 1:-1, 1] = cube_faces[3, 0, :] pad_lr[5, 1:-1, 0] = cube_faces[1, -2, :] pad_lr[5, 1:-1, 1] = cube_faces[3, -2, ::-1] cube_faces = np.concatenate([cube_faces, pad_lr], 2) return map_coordinates(cube_faces, [tp, coor_y, coor_x], order=order, mode='wrap')
Example 22
Project: py360convert Author: sunset1995 File: utils.py License: MIT License | 5 votes |
def cube_h2dice(cube_h): assert cube_h.shape[0] * 6 == cube_h.shape[1] w = cube_h.shape[0] cube_dice = np.zeros((w * 3, w * 4, cube_h.shape[2]), dtype=cube_h.dtype) cube_list = cube_h2list(cube_h) # Order: F R B L U D sxy = [(1, 1), (2, 1), (3, 1), (0, 1), (1, 0), (1, 2)] for i, (sx, sy) in enumerate(sxy): face = cube_list[i] if i in [1, 2]: face = np.flip(face, axis=1) if i == 4: face = np.flip(face, axis=0) cube_dice[sy*w:(sy+1)*w, sx*w:(sx+1)*w] = face return cube_dice
Example 23
Project: py360convert Author: sunset1995 File: utils.py License: MIT License | 5 votes |
def cube_dice2h(cube_dice): w = cube_dice.shape[0] // 3 assert cube_dice.shape[0] == w * 3 and cube_dice.shape[1] == w * 4 cube_h = np.zeros((w, w * 6, cube_dice.shape[2]), dtype=cube_dice.dtype) # Order: F R B L U D sxy = [(1, 1), (2, 1), (3, 1), (0, 1), (1, 0), (1, 2)] for i, (sx, sy) in enumerate(sxy): face = cube_dice[sy*w:(sy+1)*w, sx*w:(sx+1)*w] if i in [1, 2]: face = np.flip(face, axis=1) if i == 4: face = np.flip(face, axis=0) cube_h[:, i*w:(i+1)*w] = face return cube_h
Example 24
Project: pymoo Author: msu-coinlab File: flowshop_scheduling.py License: Apache License 2.0 | 5 votes |
def visualize(problem, x, path=None, label=True): with plt.style.context('ggplot'): n_machines, n_jobs = problem.data.shape machine_times = problem.get_machine_times(x) fig = plt.figure() ax = fig.add_subplot(111) Y = np.flip(np.arange(n_machines)) for i in range(n_machines): for j in range(n_jobs): width = problem.data[i][x[j]] left = machine_times[i][j] ax.barh(Y[i], width, left=left, align='center', color='gray', edgecolor='black', linewidth=0.8 ) if label: ax.text((left + width / 2), Y[i], str(x[j] + 1), ha='center', va='center', color='white', fontsize=15) ax.set_xlabel("Time") ax.set_yticks(np.arange(n_machines)) ax.set_yticklabels(["M%d" % (i + 1) for i in Y]) ax.set_title("Makespan: %s" % np.round(problem.makespan(x), 3)) if path is not None: plt.savefig(path) plt.show()
Example 25
Project: pymoo Author: msu-coinlab File: mw.py License: Apache License 2.0 | 5 votes |
def _evaluate(self, X, out, *args, **kwargs): g = self.g1(X) f = g.reshape((-1, 1)) * np.ones((X.shape[0], self.n_obj)) f[:, 1:] *= X[:, (self.n_obj - 2)::-1] f[:, 0:-1] *= np.flip(np.cumprod(1 - X[:, :(self.n_obj - 1)], axis=1), axis=1) g0 = f.sum(axis=1) - 1 - self.LA1(0.4, 2.5, 1.0, 8.0, f[:, -1] - f[:, :-1].sum(axis=1)) out["F"] = f out["G"] = g0.reshape((-1, 1))
Example 26
Project: pymoo Author: msu-coinlab File: mw.py License: Apache License 2.0 | 5 votes |
def _evaluate(self, X, out, *args, **kwargs): g = self.g2(X) f = g.reshape((-1, 1)) * np.ones((X.shape[0], self.n_obj)) f[:, 1:] *= np.sin(0.5 * np.pi * X[:, (self.n_obj - 2)::-1]) cos = np.cos(0.5 * np.pi * X[:, :(self.n_obj - 1)]) f[:, 0:-1] *= np.flip(np.cumprod(cos, axis=1), axis=1) f_squared = (f ** 2).sum(axis=1) g0 = f_squared - (1.25 - self.LA2(0.5, 6.0, 1.0, 2.0, np.arcsin(f[:, -1] / np.sqrt(f_squared)))) * ( 1.25 - self.LA2(0.5, 6.0, 1.0, 2.0, np.arcsin(f[:, -1] / np.sqrt(f_squared)))) out["F"] = f out["G"] = g0.reshape((-1, 1))
Example 27
Project: pymoo Author: msu-coinlab File: inversion_mutation.py License: Apache License 2.0 | 5 votes |
def inversion_mutation(y, seq, inplace=True): y = y if inplace else np.copy(y) seq = seq if not None else random_sequence(len(y)) start, end = seq y[start:end + 1] = np.flip(y[start:end + 1]) return y
Example 28
Project: HorizonNet Author: sunset1995 File: inference.py License: MIT License | 5 votes |
def augment(x_img, flip, rotate): x_img = x_img.numpy() aug_type = [''] x_imgs_augmented = [x_img] if flip: aug_type.append('flip') x_imgs_augmented.append(np.flip(x_img, axis=-1)) for shift_p in rotate: shift = int(round(shift_p * x_img.shape[-1])) aug_type.append('rotate %d' % shift) x_imgs_augmented.append(np.roll(x_img, shift, axis=-1)) return torch.FloatTensor(np.concatenate(x_imgs_augmented, 0)), aug_type
Example 29
Project: Keras-BiGAN Author: manicman1999 File: bigan.py License: MIT License | 5 votes |
def __init__(self, loc, flip = True, suffix = 'png'): self.flip = flip self.suffix = suffix self.files = [] self.n = 1e10 print("Importing Images...") try: os.mkdir("data/" + loc + "-npy-" + str(im_size)) except: self.load_from_npy(loc) return for dirpath, dirnames, filenames in os.walk("data/" + loc): for filename in [f for f in filenames if f.endswith("."+str(self.suffix))]: print('\r' + str(len(self.files)), end = '\r') fname = os.path.join(dirpath, filename) temp = Image.open(fname).convert(cmode) if not size_adjusted: temp = temp.resize((im_size, im_size), Image.BILINEAR) temp = np.array(temp, dtype='uint8') self.files.append(temp) if self.flip: self.files.append(np.flip(temp, 1)) self.files = np.array(self.files) np.save("data/" + loc + "-npy-" + str(im_size) + "/data.npy", self.files) self.n = self.files.shape[0] print("Found " + str(self.n) + " images in " + loc + ".")
Example 30
Project: Keras-BiGAN Author: manicman1999 File: guess.py License: MIT License | 5 votes |
def __init__(self, loc, flip = True, suffix = 'png'): self.flip = flip self.suffix = suffix self.files = [] self.n = 1e10 print("Importing Images...") try: os.mkdir("data/" + loc + "-npy-" + str(im_size)) except: self.load_from_npy(loc) return for dirpath, dirnames, filenames in os.walk("data/" + loc): for filename in [f for f in filenames if f.endswith("."+str(self.suffix))]: print('\r' + str(len(self.files)), end = '\r') fname = os.path.join(dirpath, filename) temp = Image.open(fname).convert(cmode) if not size_adjusted: temp = temp.resize((im_size, im_size), Image.BILINEAR) temp = np.array(temp, dtype='uint8') self.files.append(temp) if self.flip: self.files.append(np.flip(temp, 1)) self.files = np.array(self.files) np.save("data/" + loc + "-npy-" + str(im_size) + "/data.npy", self.files) self.n = self.files.shape[0] print("Found " + str(self.n) + " images in " + loc + ".")