This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#===Import dependencies=== | |
import gc | |
import pickle | |
import psutil | |
import numpy as np | |
import pandas as pd | |
#===Function to track memory usage=== | |
def memory_utilization(): | |
print('Current memory utilization: {}% ...'.format(psutil.virtual_memory().percent)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gc | |
import pickle | |
import psutil | |
import numpy as np | |
import pandas as pd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pydicom, numpy as np | |
from pydicom.pixel_data_handlers.util import apply_voi_lut | |
def readDICOM(path, optimize_display=True, monochrome_correction=True): | |
dcm = pydicom.read_file(path) | |
dcm_arr = dcm.pixel_array | |
if optimize_display: | |
dcm_arr = apply_voi_lut(dcm_array, dcm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
def execute_in_shell(command, verbose=False): | |
""" | |
command -- keyword argument, takes a list as input | |
verbsoe -- keyword argument, takes a boolean value as input | |
This is a function that executes shell scripts from within python. | |
Keyword argument 'command', should be a list of shell commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from pathlib import Path | |
logging.basicConfig(level=logging.ERROR) | |
BIN_MAPS = {"Darwin": "mac", "Linux": "linux"} | |
HOME_DIR = Path("../").expanduser() | |
try: | |
import google.colab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os,gc,json,glob,shlex,random,platform,warnings,subprocess,numpy as np, \ | |
pandas as pd,matplotlib.pyplot as plt,matplotlib.image as mpimg | |
from PIL import Image | |
from tqdm.auto import tqdm | |
from scipy.stats import wilcoxon | |
from collections import namedtuple | |
from IPython.display import display | |
from matplotlib.patches import Rectangle | |
from image_manipulation import join_images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img_dir = './' | |
if IN_COLAB: | |
from google.colab import drive | |
drive.mount('/content/drive') | |
img_dir = '/content/drive/MyDrive/' | |
fairface_dir = f'{img_dir}/FairFace/' | |
if not os.path.exists(f'{fairface_dir}/fairface-img-margin125-trainval.zip'): | |
raise ValueError(f'Please check whether the FairFace dataset zip file exists at: {fairface_dir}/fairface-img-margin125-trainval.zip') | |
if not os.path.exists(f'{fairface_dir}/fairface_label_train.csv'): | |
raise ValueError(f'Please check whether the FairFace data labels csv file exists at: {fairface_dir}/fairface_label_train.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_imgID_generator(df, pairs=True): | |
num_images = len(df) | |
id1 = random.SystemRandom().choice(range(0,num_images)) | |
if pairs: | |
id2 = random.SystemRandom().choice(range(0,num_images)) | |
return id1, id2 | |
return id1 | |
def eval_conditions(df, id1, id2): | |
id_condition = id1 == id2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unzip_dir = str(data_dir.absolute()) | |
fairface_data = f'{fairface_dir}/fairface-img-margin125-trainval.zip' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img_labels = pd.read_csv(fairface_data_checks(fairface_data)) | |
img_labels.head() | |
num_images = len(img_labels) | |
print(f'Total number of FairFace images: {num_images}') |
OlderNewer