Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions .github/workflows/test-modified.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ on:

concurrency:
# automatically cancel the previously triggered workflows when there's a newer version
group: build-gpu-${{ github.event.pull_request.number || github.ref }}
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
if: github.repository == 'Project-MONAI/tutorials'
container:
image: nvcr.io/nvidia/pytorch:24.02-py3
options: --gpus all --ipc host
runs-on: [self-hosted, linux, x64]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install MONAI
id: monai-install
run: |
which python
nvidia-smi
rm -rf ../../MONAI/MONAI
python -m pip install --upgrade pip wheel
pip uninstall -y monai
pip uninstall -y monai
pip uninstall -y monai-weekly
pip uninstall -y monai-weekly # make sure there's no existing installation
BUILD_MONAI=0 python -m pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI
python -m pip install -U pip wheel
python -m pip install torch torchvision torchaudio

python -m pip install -r https://raw.githubusercontent.com/Project-MONAI/MONAI/dev/requirements-dev.txt
python -m pip install -U torch torchvision torchaudio
- uses: actions/checkout@v3
python -m pip install -r requirements.txt

BUILD_MONAI=0 python -m pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI
python -m pip list
- name: Notebook quick check
shell: bash
run: |
git config --global --add safe.directory /__w/tutorials/tutorials
git fetch origin main
python -m pip install -r requirements.txt; python -m pip list
python -c "import monai; monai.config.print_debug_info()"
export CUDA_VISIBLE_DEVICES=0
git diff --name-only origin/main | while read line; do if [[ $line == *.ipynb ]]; then ./runner.sh -p " -and -wholename './${line}'"; fi; done;
# [[ $line == *.ipynb ]] && ./runner.sh --file "$line"
git fetch origin main
git diff --name-only origin/main | while read line
do
if [[ $line == *.ipynb ]]
then
./runner.sh -p " -and -wholename './${line}'"
fi
done
17 changes: 5 additions & 12 deletions 2d_classification/monai_101.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/workspace/data\n"
]
}
],
"outputs": [],
"source": [
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
"if directory is not None:\n",
Expand Down Expand Up @@ -250,11 +242,12 @@
"outputs": [],
"source": [
"max_epochs = 5\n",
"model = densenet121(spatial_dims=2, in_channels=1, out_channels=6).to(\"cuda:0\")\n",
"device = torch.device(\"cuda:0\" if torch.cuda.device_count() > 0 else \"cpu\")\n",
"model = densenet121(spatial_dims=2, in_channels=1, out_channels=6).to(device)\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"trainer = SupervisedTrainer(\n",
" device=torch.device(\"cuda:0\"),\n",
" device=device,\n",
" max_epochs=max_epochs,\n",
" train_data_loader=DataLoader(dataset, batch_size=512, shuffle=True, num_workers=4),\n",
" network=model,\n",
Expand Down Expand Up @@ -320,7 +313,7 @@
"max_items_to_print = 10\n",
"with eval_mode(model):\n",
" for item in DataLoader(testdata, batch_size=1, num_workers=0):\n",
" prob = np.array(model(item[\"image\"].to(\"cuda:0\")).detach().to(\"cpu\"))[0]\n",
" prob = np.array(model(item[\"image\"].to(device)).detach().to(\"cpu\"))[0]\n",
" pred = class_names[prob.argmax()]\n",
" gt = item[\"class_name\"][0]\n",
" print(f\"Class prediction is {pred}. Ground-truth: {gt}\")\n",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ autopep8
jupytext<=1.16.3
autoflake
ipywidgets
ipykernel
tensorboard>=2.4.0
18 changes: 9 additions & 9 deletions runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ trap finish EXIT
# After setup, don't want to exit immediately after error
set +e

# FIXME: https://github.com/Project-MONAI/MONAI/issues/4354
protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1)
if [ "$protobuf_major_version" -ge "4" ]
then
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
else
unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
fi

########################################################################
# #
# loop over files #
Expand Down Expand Up @@ -559,15 +568,6 @@ for file in "${files[@]}"; do

python -c 'import monai; monai.config.print_config()'

# FIXME: https://github.com/Project-MONAI/MONAI/issues/4354
protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1)
if [ "$protobuf_major_version" -ge "4" ]
then
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
else
unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
fi

cmd=$(echo "papermill ${papermill_opt} --progress-bar --log-output -k ${kernelspec}")
echo "$cmd"
time out=$(echo "$notebook" | eval "$cmd")
Expand Down
Loading