cerebralshadow
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # UKAN Segmentation Project This project implements and trains a UKAN (U-Net with Kolmogorov-Arnold Networks) model for semantic segmentation tasks on various medical imaging datasets. ## Features * Supports training on ISIC, Lumbar Spine, and Fetus Head datasets. * Implements standard UKAN architecture (`archs.py`). * Includes an optional **upgraded** UKAN architecture (`archs_upgraded.py`). * Saves training logs (`log.csv`), configuration (`config.yml`), and model checkpoints (`model.pth`, `model_epoch_X.pth`). * Visualizes segmentation progress during training, saving comparison images (`progress_images/segOutputEpoch_X.png`). * Includes an evaluation script (`evaluate.py`) for assessing trained models. ## Setup 1. **Clone the repository:** ```bash git clone https://github.com/sath-vik/Improving-Medical-Image-Segmentation-Models.git cd Improving-Medical-Image-Segmentation-Models ``` 2. **Create a virtual environment (recommended):** ```bash python -m venv venv ``` 3. **Activate the virtual environment:** * **On Linux/macOS:** ```bash source venv/bin/activate ``` * **On Windows:** ```bash venv\Scripts\activate ``` 4. **Install dependencies:** ```bash # Install PyTorch first (adjust CUDA version if needed) pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 # Or your specific CUDA version # Install other requirements pip install medpy tensorboardX timm pandas numpy PyYAML scikit-learn tqdm albumentations matplotlib scikit-image ``` *(Note: Check the official PyTorch website for the correct installation command based on your OS, package manager, and CUDA version: [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/))* ## Dataset Preparation 1. Download the required datasets (ISIC 2017, Lumbar Spine, Fetus Head). Ensure you agree to the terms and conditions of each dataset. 2. Organize the datasets according to the structure expected by the `train.py` script. The script uses the `--data_dir` argument to locate the base directory for each dataset. The default paths used in the examples are: * `/content/drive/MyDrive/Datasets/ISIC` * `/content/drive/MyDrive/Datasets/Lumbar_Spine/` * `/content/drive/MyDrive/Datasets/Fetus_Head` 3. **Expected Directory Structure within `--data_dir`:** * **For `--dataset ISIC`:** The script expects separate folders for training and validation images/masks within the `data_dir`. ``` <data_dir>/ ├── ISIC-2017_Training_Data/ │ ├── ISIC_0000000.jpg │ └── ... (training images) ├── ISIC-2017_Training_Part1_GroundTruth/ │ ├── ISIC_0000000_segmentation.png │ └── ... (training masks) ├── ISIC-2017_Validation_Data/ │ ├── ISIC_0000002.jpg │ └── ... (validation images) └── ISIC-2017_Validation_Part1_GroundTruth/ ├── ISIC_0000002_segmentation.png └── ... (validation masks) ``` *(Image files should be `.jpg`, mask files should be `.png` and end with `_segmentation.png`)* * **For `--dataset Lumbar_Spine`:** The script expects a specific structure within a `png` subdirectory inside `data_dir`. Images and masks are organized by 'Case'. The script performs an 80/20 train/validation split internally based on the files found. ``` <data_dir>/ └── png/ ├── images/ │ ├── Case_01/ │ │ ├── Slice_01.png │ │ └── ... │ └── Case_XX/ │ └── ... (image slices) └── masks/ ├── Case_01/ │ ├── Labels_Slice_01.png │ └── ... └── Case_XX/ └── ... (corresponding mask slices) ``` *(Image filenames contain `Slice_YY.png`, corresponding mask filenames must be `Labels_Slice_YY.png`)* * **For `--dataset Fetus_Head`:** The script expects separate `training_set` and `validation_set` folders. Within each folder, both images and their corresponding annotation masks reside. ``` <data_dir>/ ├── training_set/ │ ├── image_001.png │ ├── image_001_Annotation.png │ └── ... (training images and masks together) └── validation_set/ ├── image_101.png ├── image_101_Annotation.png └── ... (validation images and masks together) ``` *(Image files are `.png`, mask files are `.png` and end with `_Annotation.png`)* 4. *(Optional)* If your datasets are located elsewhere, you will need to adjust the `--data_dir` argument in the training and evaluation commands accordingly. ## Training Use the `train.py` script to train the model. Select the dataset using the `--dataset` argument and provide the correct path using `--data_dir`. **Using Standard UKAN Architecture (`archs.py`):** * **ISIC Dataset:** ```bash python train.py --dataset ISIC --data_dir '/content/drive/MyDrive/Datasets/ISIC' --name isic_ukan_standard --epochs 30 -b 8 ``` * **Lumbar Spine Dataset:** ```bash # Note: Lumbar spine uses 1 input channel python train.py --dataset Lumbar_Spine --data_dir '/content/drive/MyDrive/Datasets/Lumbar_Spine/' --name lumbar_ukan_standard --epochs 30 -b 8 --input_channels 1 ``` * **Fetus Head Dataset:** ```bash # Note: Fetus Head uses 1 input channel python train.py --dataset Fetus_Head --data_dir '/content/drive/MyDrive/Datasets/Fetus_Head' --name fetus_ukan_standard --epochs 30 -b 8 --input_channels 1 ``` **Using Upgraded UKAN Architecture (`archs_upgraded.py`):** To use the upgraded architecture defined in `archs_upgraded.py`, simply add the `--upgrade` flag to any of the training commands above. Make sure the `archs_upgraded.py` file exists in the same directory. * **Example (ISIC Dataset with Upgraded Arch):** ```bash python train.py --dataset ISIC --data_dir '/content/drive/MyDrive/Datasets/ISIC' --name isic_ukan_upgraded --epochs 30 -b 8 --upgrade ``` *You can customize other arguments like `--epochs`, `--batch_size` (`-b`), `--lr`, `--arch` (if you have multiple models within the files), `--name` (for experiment tracking), etc. Run `python train.py --help` to see all available options.* ## Outputs During and after training, the following outputs will be generated in the directory specified by `--output_dir` (default: `/content/drive/MyDrive/Codes_ADL_Assignment/Seg_UKAN/outputs`), under a subfolder named using the `--name` argument (e.g., `isic_ukan_standard`): - **`config.yml`**: The configuration file used for the training run. - **`log.csv`**: A CSV file containing training and validation metrics per epoch (e.g., loss, IoU, Dice score). - **`model.pth`**: The model checkpoint corresponding to the best validation IoU achieved during training. - **`archs_used.py`**: A copy of the architecture file used for the run (`archs.py` or `archs_upgraded.py`). - **`progress_images/`**: A folder containing sample segmentation visualizations saved during training (e.g., `segOutputEpoch_X.png`). ## Evaluation Use the `evaluate.py` script to evaluate a trained model checkpoint. You need to specify the path to the saved model (`--model_path`), the dataset (`--dataset`), the data directory (`--data_dir`), and the architecture (`--arch`) used for training. Ensure that the input channels (`--input_channels`), input height (`--input_h`), and input width (`--input_w`) match the training configuration. **Example:** For an ISIC model trained with the standard UKAN architecture: ```bash python evaluate.py \ --model_path '/content/drive/MyDrive/Codes_ADL_Assignment/Seg_UKAN/outputs/isic_ukan_standard/model.pth' \ --data_dir '/content/drive/MyDrive/Datasets/ISIC/' \ --dataset ISIC \ --arch UKAN \ --input_channels 3 \ --input_h 256 \ --input_w 256 ``` Run python evaluate.py --help to see all available evaluation options.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully