def __getitem__(self, idx): """Returns tuple (input, target) correspond to batch #idx.""" entry = self.entries[idx] entry = entry.split(',') n_entries = int(len(entry[3:]) / 9) path, W, H = entry[0:3] W = int(W) H = int(H) sf = self.target_shape[np.argmax([H, W])] / max(H, W) X = LoadImg2(path, target_shape=self.target_shape, scale_images=self.scale_images, preprocess=self.preprocess) X = np.reshape( X, (self.batch_size, self.target_shape[0], self.target_shape[1], 1)) Y = np.zeros(target_shape) for i in range(n_entries): x, y, w, h = entry[3 + 9 * i:3 + 9 * i + 4] x = sf * float(x) y = sf * float(y) w = sf * float(w) h = sf * float(h) Y[int(y - h / 2):int(y + h / 2), int(x - w / 2):int(x + w / 2)] = 1 return X, Y
def XY(entry, target_shape=(416, 416), S=(16, 16), scale_images=True, preprocess=True): x = LoadImg2(entry.split(',')[0], target_shape=target_shape, scale_images=scale_images, preprocess=preprocess) x = np.reshape(x, (target_shape[0], target_shape[1], 1)) y = YOLOBrick(entry, S=S, target_shape=target_shape, scale_images=scale_images) return x, y
def __getitem__(self, idx): """Returns tuple (input, target) correspond to batch #idx.""" entry = self.entries[idx] path = entry.split(',')[0] x = LoadImg2(path, target_shape=self.target_shape, scale_images=self.scale_images, preprocess=self.preprocess) x = np.reshape( x, (self.batch_size, self.target_shape[0], self.target_shape[1], 1)) y = YOLOBrick(entry, S=self.S, target_shape=self.target_shape, size_thresh=self.size_thresh, scale_images=self.scale_images) return x, y
def XY(entry, target_shape=(640, 640), scale_images=True, preprocess=True): entry = entry.split(',') n_entries = int(len(entry[3:]) / 9) path, W, H = entry[0:3] W = int(W) H = int(H) sf = target_shape[np.argmax([H, W])] / max(H, W) X = LoadImg2(path, target_shape=target_shape, scale_images=scale_images, preprocess=preprocess) X = np.reshape(X, (1, target_shape[0], target_shape[1], 1)) Y = np.zeros(target_shape) for i in range(n_entries): x, y, w, h = entry[3 + 9 * i:3 + 9 * i + 4] x = sf * float(x) y = sf * float(y) w = sf * float(w) h = sf * float(h) Y[int(y - h / 2):int(y + h / 2), int(x - w / 2):int(x + w / 2)] = 1 return X, Y
def XY(entry, target_shape=(416, 416), S=(16, 16), C=10): x = LoadImg2(entry.split(',')[0], target_shape=target_shape) x = np.reshape(x, (target_shape[0], target_shape[1], 1)) y = YOLOBrick(entry, S=S, C=C, target_shape=target_shape) return x, y
def __getitem__(self, idx): """Returns tuple (input, target) correspond to batch #idx.""" entry = self.entries[idx] path = entry.split(',')[0] W = int(entry.split(',')[1]) H = int(entry.split(',')[2]) sf = self.resized_shape[np.argmax([H, W])] / max(H, W) grid_h = self.input_shape[0] / self.S[0] grid_w = self.input_shape[1] / self.S[1] big_frame = LoadImg2(path, target_shape=self.resized_shape) # Create tile images & model outputs X = np.zeros((4, self.input_shape[0], self.input_shape[1], 1)) X[0, :, :, 0] = big_frame[0:self.input_shape[0], 0:self.input_shape[1]] X[1, :, :, 0] = big_frame[self.input_shape[0]:2 * self.input_shape[0], 0:self.input_shape[1]] X[2, :, :, 0] = big_frame[0:self.input_shape[0], self.input_shape[1]:2 * self.input_shape[1]] X[3, :, :, 0] = big_frame[self.input_shape[0]:2 * self.input_shape[0], self.input_shape[1]:2 * self.input_shape[1]] # Create output brick Y = np.zeros((4, self.S[0], self.S[1], (5 * self.B))) # For each annotation... entry = entry.split(',') n_entries = int(len(entry[3:]) / 9) for n in range(n_entries): # Read entry data x, y, w, h, label, pxmin, pymin, pxmax, pymax = entry[3 + 9 * n:3 + 9 * (n + 1)] x = float(x) y = float(y) w = float(w) h = float(h) pxmin = int(pxmin) pymin = int(pymin) pxmax = int(pxmax) pymax = int(pymax) x = x - pxmin y = y - pymin # Transform coordinates sf = self.resized_shape[np.argmax([ pymax - pymin, pxmax - pxmin ])] / max(pymax - pymin, pxmax - pxmin) x = sf * x y = sf * y h = sf * h / self.input_shape[0] w = sf * w / self.input_shape[1] tile_row = int(np.floor(y / self.input_shape[0])) tile_col = int(np.floor(x / self.input_shape[1])) if tile_row == 0 and tile_col == 0: tile_idx = 0 if tile_row == 1 and tile_col == 0: tile_idx = 1 if tile_row == 0 and tile_col == 1: tile_idx = 2 if tile_row == 1 and tile_col == 1: tile_idx = 3 x = x - tile_col * self.input_shape[1] y = y - tile_row * self.input_shape[0] cell = (int(np.floor(y / grid_h)), int(np.floor(x / grid_w))) x = (x - cell[1] * grid_w) / grid_w y = (y - cell[0] * grid_h) / grid_h # Assign entry to corresponding node Y[tile_idx, cell[0], cell[1], :] = [x, y, w, h, 1] return X, Y
def XY(entry, S=(16, 16), B=1, input_shape=(416, 416)): resized_shape = (2 * input_shape[0], 2 * input_shape[1]) path = entry.split(',')[0] W = int(entry.split(',')[1]) H = int(entry.split(',')[2]) sf = resized_shape[np.argmax([H, W])] / max(H, W) grid_h = input_shape[0] / S[0] grid_w = input_shape[1] / S[1] big_frame = LoadImg2(path, target_shape=resized_shape) # Create tile images & model outputs X = np.zeros((4, input_shape[0], input_shape[1], 1)) X[0, :, :, 0] = big_frame[0:input_shape[0], 0:input_shape[1]] X[1, :, :, 0] = big_frame[input_shape[0]:2 * input_shape[0], 0:input_shape[1]] X[2, :, :, 0] = big_frame[0:input_shape[0], input_shape[1]:2 * input_shape[1]] X[3, :, :, 0] = big_frame[input_shape[0]:2 * input_shape[0], input_shape[1]:2 * input_shape[1]] # Create output brick Y = np.zeros((4, S[0], S[1], (5 * B))) # For each annotation... entry = entry.split(',') n_entries = int(len(entry[3:]) / 9) for n in range(n_entries): # Read entry data x, y, w, h, label, pxmin, pymin, pxmax, pymax = entry[3 + 9 * n:3 + 9 * (n + 1)] x = float(x) y = float(y) w = float(w) h = float(h) pxmin = int(pxmin) pymin = int(pymin) pxmax = int(pxmax) pymax = int(pymax) x = x - pxmin y = y - pymin # Transform coordinates sf = resized_shape[np.argmax([pymax - pymin, pxmax - pxmin])] / max( pymax - pymin, pxmax - pxmin) x = sf * x y = sf * y h = sf * h / input_shape[0] w = sf * w / input_shape[1] tile_row = int(np.floor(y / input_shape[0])) tile_col = int(np.floor(x / input_shape[1])) if tile_row == 0 and tile_col == 0: tile_idx = 0 if tile_row == 1 and tile_col == 0: tile_idx = 1 if tile_row == 0 and tile_col == 1: tile_idx = 2 if tile_row == 1 and tile_col == 1: tile_idx = 3 x = x - tile_col * input_shape[1] y = y - tile_row * input_shape[0] cell = (int(np.floor(y / grid_h)), int(np.floor(x / grid_w))) x = (x - cell[1] * grid_w) / grid_w y = (y - cell[0] * grid_h) / grid_h # Assign entry to corresponding node Y[tile_idx, cell[0], cell[1], :] = [x, y, w, h, 1] return X, Y