### Installation: Clone Repository and Run Example Source: https://github.com/jeremykawahara/derm7pt/blob/master/README.md These commands show how to clone the derm7pt repository and execute the minimal example script. Ensure you change the directory path to match your data folder. ```bash git clone https://github.com/jeremykawahara/derm7pt.git cd derm7pt python minimal_example.py '/local-scratch/jer/data/argenziano/release_v0' ``` -------------------------------- ### Import Libraries and Setup Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/web_images.ipynb Imports necessary libraries like matplotlib, pandas, and json, and sets up the environment for autoreload and inline plotting. It also configures pandas display options and adjusts the system path. ```python from __future__ import print_function, division %load_ext autoreload %autoreload 2 %matplotlib inline import matplotlib.pyplot as plt import pandas as pd pd.set_option('display.max_columns', 500) import json import sys, os from shutil import copyfile sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..'))) ``` -------------------------------- ### Check Pandas Version Source: https://github.com/jeremykawahara/derm7pt/blob/master/version_check.ipynb Verify the Pandas library version. Ensure Pandas is installed and imported. ```python import pandas pandas.__version__ ``` -------------------------------- ### Get Validation Image Paths Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/example.ipynb Demonstrates how to retrieve validation image paths. These are typically used for hyper-parameter tuning. ```python # Note, you can get images for validation by: valid_derm_paths = derm_data_group.get_img_paths(data_type='valid', img_type='derm') print(len(valid_derm_paths)) # We don't use them within this demo, but they could/should be used when choosing hyper-parameters. ``` -------------------------------- ### Check Python Version Source: https://github.com/jeremykawahara/derm7pt/blob/master/version_check.ipynb Use this snippet to verify the installed Python version. It requires the `sys` module. ```python # Python version. import sys sys.version ``` -------------------------------- ### Check NumPy Version Source: https://github.com/jeremykawahara/derm7pt/blob/master/version_check.ipynb Verify the installed NumPy version. Ensure NumPy is installed and imported as `np`. ```python import numpy as np np.__version__ ``` -------------------------------- ### Load IPython Extensions and Libraries Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/example.ipynb Loads necessary IPython extensions and Python libraries for data analysis and visualization. Ensure these libraries are installed. ```python %load_ext autoreload %autoreload 2 %matplotlib inline import matplotlib.pyplot as plt plt.style.use('ggplot') import pandas as pd pd.set_option('display.max_columns', 500) import sys, os from sklearn.linear_model import LogisticRegression sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..'))) ``` -------------------------------- ### Minimal Example: Load and Preprocess Dermatology Data Source: https://github.com/jeremykawahara/derm7pt/blob/master/README.md This snippet demonstrates how to load the Seven-Point Checklist Dermatology Dataset using the Derm7PtDatasetGroupInfrequent class. It preprocesses the data by grouping infrequent class labels and assigning numeric values. ```python import sys, os import pandas as pd sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..'))) # To import derm7pt from derm7pt.dataset import Derm7PtDatasetGroupInfrequent # Change this line to your data directory. dir_release = '/local-scratch/jer/data/argenziano/release_v0' # Dataset after grouping infrequent labels. derm_data = Derm7PtDatasetGroupInfrequent( dir_images=os.path.join(dir_release, 'images'), metadata_df=pd.read_csv(os.path.join(dir_release, 'meta/meta.csv')), train_indexes=list(pd.read_csv(os.path.join(dir_release, 'meta/train_indexes.csv'))['indexes']), valid_indexes=list(pd.read_csv(os.path.join(dir_release, 'meta/valid_indexes.csv'))['indexes']), test_indexes=list(pd.read_csv(os.path.join(dir_release, 'meta/test_indexes.csv'))['indexes'])) # Outputs to screen the preprocessed dataset in a Pandas format. derm_data.df ``` -------------------------------- ### Check Scikit-learn Version Source: https://github.com/jeremykawahara/derm7pt/blob/master/version_check.ipynb Check the installed version of Scikit-learn. Import the `sklearn` module to access its version. ```python import sklearn sklearn.__version__ ``` -------------------------------- ### Get Training Image Paths and Labels Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/example.ipynb Retrieves training image paths for dermatology and clinic, along with corresponding labels. The labels dictionary contains abbreviations for diagnosis and seven criteria. ```python # Get the dermatology and clinic training images and corresponding labels. train_derm_paths = derm_data_group.get_img_paths(data_type='train', img_type='derm') train_clinic_paths = derm_data_group.get_img_paths(data_type='train', img_type='clinic') train_labels = derm_data_group.get_labels(data_type='train', one_hot=False) # The 8 abbreviations that indicate the different types of categories # i.e., 1 diagnosis + 7 critiera. print(train_labels.keys()) ``` -------------------------------- ### Check Matplotlib Version Source: https://github.com/jeremykawahara/derm7pt/blob/master/version_check.ipynb Confirm the Matplotlib version. This requires the `matplotlib` library to be installed. ```python import matplotlib matplotlib.__version__ ``` -------------------------------- ### Get Testing Image Paths and Labels Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/example.ipynb Retrieves testing image paths for dermatology and clinic, along with corresponding labels. This is used for evaluating the trained model. ```python # Get the dermatology and clinic test images and corresponding labels. test_derm_paths = derm_data_group.get_img_paths(data_type='test', img_type='derm') test_clinic_paths = derm_data_group.get_img_paths(data_type='test', img_type='clinic') test_labels = derm_data_group.get_labels(data_type='test', one_hot=False) ``` -------------------------------- ### Define Data Directories Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/example.ipynb Sets up the directory paths for the dataset's release meta-data and images. Make sure to change 'dir_release' to your actual data directory. ```python # CHANGE THIS LINE TO YOUR DATA DIRECTORY. dir_release = '/local-scratch/jer/data/argenziano/release_v0' dir_meta = os.path.join(dir_release, 'meta') dir_images = os.path.join(dir_release, 'images') ``` -------------------------------- ### Initialize Derm7Pt Datasets Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/example.ipynb Creates instances of Derm7PtDataset and Derm7PtDatasetGroupInfrequent. The first handles the full dataset, while the second groups infrequent labels. Both require image directory, metadata, and data split indices. ```python # The full dataset before any grouping of the labels. derm_data = Derm7PtDataset(dir_images=dir_images, metadata_df=meta_df.copy(), # Copy as is modified. train_indexes=train_indexes, valid_indexes=valid_indexes, test_indexes=test_indexes) # The dataset after grouping infrequent labels. derm_data_group = Derm7PtDatasetGroupInfrequent(dir_images=dir_images, metadata_df=meta_df.copy(), # Copy as is modified. train_indexes=train_indexes, valid_indexes=valid_indexes, test_indexes=test_indexes) ``` -------------------------------- ### Load Dataset Metadata and Indices Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/example.ipynb Reads CSV files to load the main metadata, and the indices for training, validation, and testing sets. These are crucial for initializing the dataset objects. ```python meta_df = pd.read_csv(os.path.join(dir_meta, 'meta.csv')) train_indexes = list(pd.read_csv(os.path.join(dir_meta, 'train_indexes.csv'))['indexes']) valid_indexes = list(pd.read_csv(os.path.join(dir_meta, 'valid_indexes.csv'))['indexes']) test_indexes = list(pd.read_csv(os.path.join(dir_meta, 'test_indexes.csv'))['indexes']) ``` -------------------------------- ### Load and Inspect Derm7Pt Dataset Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/minimal_example.ipynb Use this snippet to load the Derm7Pt dataset with infrequent labels grouped. Ensure the `dir_release` variable points to your data directory. This code preprocesses the dataset and displays its initial rows. ```python import sys, os import pandas as pd sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..'))) # To import derm7pt from derm7pt.dataset import Derm7PtDatasetGroupInfrequent # Change this line to your data directory. dir_release = '/local-scratch/jer/data/argenziano/release_v0' # Dataset after grouping infrequent labels. derm_data = Derm7PtDatasetGroupInfrequent( dir_images=os.path.join(dir_release, 'images'), metadata_df=pd.read_csv(os.path.join(dir_release, 'meta/meta.csv')), train_indexes=list(pd.read_csv(os.path.join(dir_release, 'meta/train_indexes.csv'))['indexes']), valid_indexes=list(pd.read_csv(os.path.join(dir_release, 'meta/valid_indexes.csv'))['indexes']), test_indexes=list(pd.read_csv(os.path.join(dir_release, 'meta/test_indexes.csv'))['indexes'])) # Outputs to screen the first 5 rows of the preprocessed dataset in a Pandas format. derm_data.df.head(n=5) ``` -------------------------------- ### Load Pretrained MobileNet Model Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/example.ipynb Loads a pre-trained MobileNet model for feature extraction. Ensure the input shape is compatible with the model. ```python # Choose a pretrained model to extract features from. # Can use any model. Just have to make sure the input_shape is appropriate. from keras.applications.mobilenet import MobileNet, preprocess_input input_shape = (224, 224, 3) model = MobileNet(include_top=False, input_shape=input_shape) ``` -------------------------------- ### Check Pillow Version Source: https://github.com/jeremykawahara/derm7pt/blob/master/version_check.ipynb Confirm the Pillow (PIL fork) version. Import the `PIL` module to check its version. ```python import PIL PIL.__version__ ``` -------------------------------- ### HTML Structure Definitions Source: https://github.com/jeremykawahara/derm7pt/blob/master/notebooks/web_images.ipynb Defines the HTML header and footer templates used for creating web pages. These include Bootstrap CSS for styling and container divs for layout. ```python html_header = '''