def read_data(idx): name, label = sample_list[idx] d = np.load(os.path.join(DATA_DIR, name + '.npz')) pix = zero_center(normalize(d['pix_resampled'])) # set all outside regions to zero pix *= d['segmented_lungs_fill_dilated'] return pix, label
# Load training labels sample_list = [] with open(LABLE_FILE_TRAIN) as f: for name, label in csv.reader(f): sample_list.append((name, float(label))) num_samples = len(sample_list) print('number of samples:', num_samples) # Pre-load all the data data_list = [None] * num_samples label_list = [None] * num_samples for idx in range(num_samples): print('pre-loading data %d / %d' % (idx + 1, len(sample_list))) name, label = sample_list[idx] d = np.load(os.path.join(DATA_DIR, name + '.npz')) pix = zero_center(normalize(d['pix_resampled_add0'])).astype(np.float32) data_list[idx] = pix label_list[idx] = label d.close() batch_data = np.zeros((N, Z, Y, X, 1), np.float32) batch_labels = np.zeros((N, 1), np.float32) def get_random_samples(): inds = np.random.choice(num_samples, N, replace=False) for i, idx in enumerate(inds): batch_data[i, ..., 0] = data_list[idx] batch_labels[i] = label_list[idx] return batch_data, batch_labels
def read_data(idx): name, label = sample_list[idx] d = np.load(os.path.join(DATA_DIR, name + '.npz')) pix = zero_center(normalize(d['pix_resampled_add0'])) return pix, label