Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhang02 committed Oct 3, 2024
1 parent a17e8dc commit 5904504
Show file tree
Hide file tree
Showing 32 changed files with 1,284 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Note/Tech-Reports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Technical-Reports
This repo collects my unperfect technical reports during my study, where these reports contains good and bad experiment results.

* [[201903] Technical report -> unet](/reports/Technical_Report_201903_UNet.pdf)
* [[201904] Technical report -> segmentation and loss](/reports/Technical_Report_201904_SegmentationLoss.pdf)
* [[201909] Technical report -> multiclass segmentation](/reports/Technical_Report_201909_MulticlassSegmentation.pdf)
* [[201910] Technical report -> kappa loss](/reports/Technical_Report_201910_Kappaloss.pdf)
* [[201912] Technical report -> vnet](/reports/Technical_Report_201912_VNet.pdf)
* [[202001] Technical report -> deep bayesian](/reports/Technical_Report_202001_DeepBayesian.pdf)
* [[202001] Technical report -> regression cnn](/reports/Technical_Report_202001_RegressionCNN.pdf)
* [[202008] Technical report -> explainable ai](/reports/Technical_Report_202008_XAI.pdf)
* [[202104] Technical report -> acdc dataset](/reports/Technical_Report_202104_ACDC.pdf)
* [[202110] Technical report -> head circumference and cardiac volume prediction](/reports/Technical_Report_202110_HCACDC.pdf)
* [[202111] Technical report -> vit](/reports/Technical_Report_202111_ViT.pdf)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions Note/docs/CuPy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# CuPy --accelerated Numpy


### Install CuPy
CuPy is a NumPy compatible library for GPU acceleration. If your computing tasks require a lot of matrix operations and you have GPU resources available, Cupy can help you accelerate these operations.

install steps:
* `python -m pip install -U setuptools pip`
* `pip install cupy-cuda12x`

For more details: see [https://docs.cupy.dev/en/stable/install.html](https://docs.cupy.dev/en/stable/install.html)
### Install CUDA
* install: go to the official website [https://developer.nvidia.com/cuda-downloads](https://developer.nvidia.com/cuda-downloads)
* check: `nvcc --version`
### Example
```
import cupy as cp
from cupyx.scipy.signal import convolve2d
from cupyx.scipy import ndimage
```
almost all the numpy functions are compatible to cupy.
### Docker
Use NVIDIA Container Toolkit to run CuPy image with GPU.
☑️ Strategy 1: `docker run --gpus all -it cupy/cupy /bin/bash`
☑️ Strategy 2: `docker run --gpus all -it cupy/cupy /usr/bin/python3`
☑️ Strategy 3: use Singularity to build a `sif` image
* `sudo singularity -d build --sandbox sandbox_cupy/ docker://cupy/cupy`
* `sudo singularity shell --writable sandbox_cupy/`
* `pip install pythonlibs` pythonlibs that you need
* `sudo singularity build cupy.sif sandbox_cupy/`

64 changes: 64 additions & 0 deletions Note/docs/DL-workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Workflow of training a deep learning model
### Table of contents
* [Prepare dataset](#prepare-dataset)
* [Architechture](#architecture)
* [Set up environment](#set-up-environment)
* [Training](#training)
* [Testing](#testing)
* [Evaluation](#evaluation)
* [Common errors](#commen-errors)

### Prepare dataset
### Architecture
☑️ CNN
☑️ GAN
☑️ Transformer
☑️ SSL
☑️ USL
### Set up environment
☑️ CPU or GPU
☑️ Epochs
☑️ Learning rate
☑️ Batch size
☑️ Optimizer
☑️ Scheduler
☑️ Log save for loss metric curves.

### Training
☑️ Strategy 1: Two-step pipeline. For instance, coarse segmentation (ROI detection) --> fine segmentation.
☑️ Strategy 2: Compound loss functions. Main loss and auxiliary loss with weights. For instance, Dice+CE, Dice+Focal.
☑️ Strategy 3: Think if a gradient is needed in some parts.
☑️ Strategy 4: Training time augmentation (TTA).

### Testing
☑️ test-time-training (TTT) if necessary
### Evaluation
☑️ Metrics
### Common errors
⁉️ **RuntimeError**: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.
💠 Solution1: `retain_graph=True`
💠 Solution2: check `torch.no_grad()` and `var.detach()`
⁉️ **AttributeError**: 'float' object has no attribute 'backward'
💠 Solution: `object.ToTensor()`
⁉️ RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1024, 27648]], which is output 0 of AsStridedBackward0, is at version 3; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
💠 Solution: `output_copy = output.clone() # avoid in-place opration`
⁉️ **IndexError**: Dimension out of range (expected to be in range of [-2, 1], but got 2)
💠 Solution: check data shape
⁉️ AttributeError: 'tuple' object has no attribute 'shape'
💠 Solution: check data shape convert to `a_array = np.array(a); print(a_array.shape) # (3,)`
⁉️ RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn in `total_loss.backward()`
💠 Solution: check the loss definition, it should have a gradient.
⁉️ **IndentationError**: unindent does not match any outer indentation level
💠 Solution: check indent

⁉️ **TypeError**: `logits = torch.squeeze(logits,dim=1)` squeeze() received an invalid combination of arguments - got (tuple, dim=int), but expected one of:
* (Tensor input)
* (Tensor input, int dim)
didn't match because some of the arguments have invalid types: (!tuple of (Tensor, Tensor)!, dim=int)
* (Tensor input, tuple of ints dim)
didn't match because some of the arguments have invalid types: (!tuple of (Tensor, Tensor)!, !dim=int!)
* (Tensor input, name dim)
didn't match because some of the arguments have invalid types: (!tuple of (Tensor, Tensor)!, !dim=int!)

💠 Solution: check datatype and dimension

84 changes: 84 additions & 0 deletions Note/docs/Install-C++.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Install C++ compiler
One figure to explain why a compiler is needed:
![operating system history](./fig/history-OS.png)

## On Linux/WSL
### GCC
GCC (Usually it's pre-installed), just need to check version `gcc --version`

### MinGW-w64
Mingw-w64 is installed on Linux to cross-compile Windows applications, that is, to compile executable files or libraries (.dll) on Linux that can run on Windows.

e.g. in Ubuntu:
```
sudo apt update
sudo apt install mingw-w64
```
in Fedora/CentOS, use `yum` or `dnf`:
```
sudo yum install mingw64-gcc mingw64-binutils
```
in Arch Linux
```
sudo pacman -S mingw-w64
```
check version for 64-bit and 32-bit:
```
x86_64-w64-mingw32-gcc --version
i686-w64-mingw32-gcc --version
```

compile a c file for 64-bit and 32-bit into executable or libs files:

```
x86_64-w64-mingw32-gcc -o hello.exe hello.c
x86_64-w64-mingw32-gcc -shared -o hello64.dll hello.c
i686-w64-mingw32-gcc -o hello32.exe hello.c
i686-w64-mingw32-gcc -shared -o hello32.dll hello.c
```

## On Windows

### MinGW-w64
[Mingw-w64](https://www.mingw-w64.org/) is an advancement of the original mingw.org project, created to support the GCC compiler on Windows systems.
Mingw-w64 interacts a lot with other projects in order to help everyone move forward. Contributions have been going to and coming from these projects:
* [Cygwin](https://cygwin.com/index.html): Get that Linux feeling - on Windows
* ReactOS
* Wine
* [MSYS2](https://www.msys2.org/): Cygwin provides a large collection of packages containing such software, and libraries for their development.

For example, in MSYS2 terminal (after you installed it), install the MinGW-w64 toolchain by running the following command
```
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
```

🫰tips:
* `pacman` is a package manager (in Arch Linux). Similar to `apt` (in Ubuntu) or `yum` (in CentOS) etc.
* `-S` indicates installation of the specified software package.
* `needed` indicates that only packages that are not currently installed on the system will be installed (installed packages will be skipped).
* `base-devel` a package group that includes basic development tools (such as make, gcc, gdb, etc.).
* `mingw-w64-ucrt-x86_64-toolchain` the toolchain package of Mingw-w64, based on the UCRT runtime library, supporting 64-bit Windows compilation and development.
* `ucrt` (Universal C Runtime) is a modern universal C runtime library on Windows that provides standard library support for C and C++.

After installation, add the path of your MinGW-w64 `bin` folder to the Windows `PATH` environment variable by using the following steps:

1. In the Windows search bar, type **Settings** to open your Windows Settings.
2. Search for **Edit environment variables for your account**.
3. In your **User variables**, select the `Path` variable and then select **Edit**.
4. Select **New** and add the MinGW-w64 destination folder you recorded during the installation process to the list. If you used the default settings above, then this will be the path: `C:\msys64\ucrt64\bin`.
5. Select **OK**, and then select **OK** again in the **Environment Variables** window to update the `PATH` environment variable. You have to **restart** the computer for the updated `PATH` environment variable to be available.

Check version
```
gcc --version
g++ --version
gdb --version
```
### MSVS
Microsoft Visual Studio (MSVS) is an integrated development environment (IDE) provided by Microsoft that supports multiple programming languages, including C, C++, C#, Python, etc. Visual Studio uses MSVC (Microsoft Visual C++ Compiler) to compile C and C++ programs. It's very big!


## On MAC (TODO)
I don't have a mac yet.
30 changes: 30 additions & 0 deletions Note/docs/Install-OpenGATE-on-WSL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Install OpenGATE
## Install OpenGATE on WSL
### Preface
#### 🧐 What is OpenGATE?
Geant4 is a general particle transport simulation tool, while GATE is a specific application based on Geant4, focusing on simulation and simulation in the field of nuclear medicine. OpenGATE is based on GATE, which is written in Python language, it is a work in progress.

#### 🧐 What is WSL?
Windows Subsystem Linux (WSL). We can regard this system as a duo system (Windows and Linux) or a virtual machine, anyway, it's convenient to use both two systems.

### Installation

1. Install WSL: open CMD, input `wsl --install`, for detail, see [Official tutorial](https://learn.microsoft.com/en-us/windows/wsl/install#Overview) .
2. Install Anaconda in WSL terminal: download the package on Win, then copy to the WSL dirctory like `home/user/`, then install it by `bash package.sh`, then following the instructions.
3. Create conda environment: input `conda create -n gate python=3.9`
4. Install OpenGATE in the `gate` environment: `pip install -pre opengate`

### Test
5. Test: input `opengate_tests` install the missing lib according to the instructions, mainly `.so` files. e.g. `conda install -c conda-forge libstdcxx-ng` `conda install qt=5` Also pay attention to step 6.
6. Declare path `export PATH="/opt/conda/envs/gate/bin:$PATH"` in the terminal(temporal) or write in the `~/.bashrc`(permanent), then `source ~/.bashrc`, to make it into effect.

## Install OpenGATE on Windows

### Installation

1. Install miniconda or Anaconda on Windows
2. Create conda environment: input `conda create -n gate python=3.9/3.10/3.11`
3. Install OpenGATE in the `gate` environment: `pip install -pre opengate` `-pre` means the latest version
Note: if one wants to update the OpenGATE, delete the gate environment and create new conda env then install as step 2. Otherwise error happens~
### Test
4. Test: input `opengate_info`, some missing data will automatically download. And in Windows, no need to declare path.
Loading

0 comments on commit 5904504

Please sign in to comment.