Beispiel #1
0
 def test_data_loader_3D(self, batch_size=1):
     for j in range(self.test_samples.size):
         dwi = self.test_hdf5s[j]['dwi1'][:]
         dwi = utils.min_max_normalize(dwi)
         dwi = np.expand_dims(dwi.transpose(0, 3, 1, 2), axis=0)
         t2ax = self.test_hdf5s[j]['t2ax_cropped'][:]
         t2ax = utils.min_max_normalize(t2ax)
         t2ax = t2ax.transpose(2, 0, 1)
         t2ax = np.expand_dims(np.expand_dims(t2ax, axis=0), axis=0)
         label = np.expand_dims(np.expand_dims(self.test_labels[j], axis=0),
                                axis=0)
         yield dwi, t2ax, label
Beispiel #2
0
 def data_loader_3D(self, batch_size=1):
     for j in range(self.all_samples.size):
         print(self.subject_ids[j])
         try:
             dwi = self.sample_hdf5s[j]['dwi1'][:]
         except:
             print('dwi1 for {} does not exist'.format(self.subject_ids[j]))
             sys.exit(1)
         dwi = utils.min_max_normalize(dwi)
         dwi = np.expand_dims(dwi.transpose(0, 3, 1, 2), axis=0)
         t2ax = self.sample_hdf5s[j]['t2ax_cropped'][:]
         t2ax = utils.min_max_normalize(t2ax)
         t2ax = t2ax.transpose(2, 0, 1)
         t2ax = np.expand_dims(np.expand_dims(t2ax, axis=0), axis=0)
         label = np.expand_dims(np.expand_dims(self.test_labels[j], axis=0),
                                axis=0)
         yield dwi, t2ax, label
Beispiel #3
0
def generate_cam(activation, fc_weights, class_idx):
    activation = reshape_for_removing_batch_size(activation)
    class_idx = reshape_for_removing_batch_size(class_idx)

    channel, height, width = activation.shape
    cam = torch.zeros([height, width], dtype=torch.float)
    fc_weight = fc_weights[class_idx]
    fc_weight = fc_weight.view(fc_weight.shape[1])
    for c in range(channel):
        cam += fc_weight[c] * activation[c]

    normalized_cam = min_max_normalize(cam)
    scaled_cam = np.uint8((normalized_cam * 255).int().numpy())
    return cv2.resize(scaled_cam, (IMG_SIZE, IMG_SIZE))
Beispiel #4
0
def main(args):
	func = args.func
	side = args.side

	if args.file_in != None and args.file_out != None and arg.mask != None:
		image_path = args.file_in
		out_path = args.file_out
		mask_path = args.mask

		mask_file = utils.read_file(mask_path)
		image_file = utils.read_file(image_path)

		masked = utils.mask(image_file[0], mask_file[0], side)

		if func == "mask":
			utils.save_file(masked, image_file[1], image_file[2], out_path)

		elif func == "normalize":
			normalized = utils.min_max_normalize(masked)
			utils.save_file(normalized, image_file[1], image_file[2], out_path)

		else:
			print('func error')

	elif args.folder_in != None :
		folder_in = args.folder_in

		if args.folder_out != None:
			folder_out = args.folder_out
		else:
			folder_out = folder_in

		image_folder = os.path.join(folder_in, 'image')
		mask_folder = os.path.join(folder_in, 'mask')

		image_files = []
		for file in os.listdir(image_folder):
			if file.endswith((".mgz", ".nii", ".nii.gz")):
				image_files.append(file)


		for file in image_files:
			image_path = os.path.join(image_folder, file)
			mask_path = os.path.join(mask_folder, file)


			if not os.path.isfile(mask_path):
				break
			image_file = utils.read_file(image_path)
			mask_file = utils.read_file(mask_path)

			masked = utils.mask(image_file[0], mask_file[0], side)

			if func == "mask":
				if file.endswith((".mgz", ".nii")):
					out_file = file[:-4] + '_masked.nii.gz'
				elif file.endswith([".nii.gz"]):
					out_file = file[:-7] + '_masked.nii.gz'
					
				out_path = os.path.join(folder_out, 'masked')
				if not os.path.exists(out_path):
					os.makedirs(out_path)
				out_path = os.path.join(out_path, out_file)
				utils.save_file(masked, image_file[1], image_file[2], out_path)

			elif func == "normalize":
				normalized = utils.min_max_normalize(masked)
				if file.endswith((".mgz", ".nii")):
					out_file = file[:-4] + '_normalized.nii.gz'
				elif file.endswith([".nii.gz"]):
					out_file = file[:-7] + '_normalized.nii.gz'
				out_path = os.path.join(folder_out, 'normalized')
				if not os.path.exists(out_path):
					os.makedirs(out_path)
				out_path = os.path.join(out_path, out_file)
				utils.save_file(normalized, image_file[1], image_file[2], out_path)

			else:
				print('func error')


	else:
		print('parameter error')
Beispiel #5
0
def _normalize(image, output):
    normalized = utils.min_max_normalize(image[0])
    utils.save_file(normalized, image[1], image[2], output)
Beispiel #6
0
        if timestamp not in turnstile:
            turnstile[timestamp] = {}
        if stamp['STATION'] not in turnstile[timestamp]:
            turnstile[timestamp][stamp['STATION']] = 0

        turnstile[timestamp][
            stamp['STATION']] += stamp['ENTRIES'] - stamp['EXITS']

    print('Normalizing...')

    for time in list(turnstile.keys()):
        values = []
        for _, key in enumerate(list(turnstile[time].keys())):
            values.append(turnstile[time][key])
        values = min_max_normalize(values)
        for index, key in enumerate(list(turnstile[time].keys())):
            turnstile[time][key] = values[index]

    print('Tensorizing...')

    original_G = ox.graph_from_place('New York City, New York, USA',
                                     network_type='drive')

    for time in list(turnstile.keys()):
        G = original_G
        fig, ax = ox.plot_graph(G,
                                show=False,
                                close=False,
                                node_size=0,
                                edge_linewidth=0)