Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
48d5c12
Setting up GitHub Classroom Feedback
github-classroom[bot] Feb 3, 2024
d9f6666
docs: Add pr, issue template
Jungtaxi Feb 6, 2024
4de8718
feat: Add black and ruff pre-commit (#4)
Jungtaxi Feb 6, 2024
6fa4e8f
feat: Ignore f403 in ruff (#6)
Jungtaxi Feb 6, 2024
ec09a9c
feat: Add pytorch template (#7)
rudeuns Feb 6, 2024
08d6e72
feat: Cutomize base_trainer
rudeuns Feb 7, 2024
8afdeb1
feat: Customize trainer
rudeuns Feb 7, 2024
d7a7418
Merge pull request #9 from boostcampaitech6/feat-#8/customize-trainer
rsl82 Feb 7, 2024
ccadbe8
feat: Add amp to trainer (#12)
rudeuns Feb 7, 2024
aa785e1
feat: Add loss functions (#17)
Jungtaxi Feb 9, 2024
79b7321
feat: Add dice metric (#19)
Jungtaxi Feb 9, 2024
8aa3f40
feat: Add fcn resnet50 model (#21)
Jungtaxi Feb 9, 2024
76bf04b
feat: Add wandb logger (#15)
rudeuns Feb 9, 2024
498ddec
feat: Modify config.json (#28)
rudeuns Feb 11, 2024
fd826df
feat: Add auto created save_dir logic (#29)
rudeuns Feb 11, 2024
7f76402
fix: Fix trainer class (#23)
rudeuns Feb 11, 2024
e41edd5
feat: Add dice metric in MetricTracker (#30)
rudeuns Feb 11, 2024
a8a86f9
refactor: Refactor code about config (#31)
rudeuns Feb 11, 2024
ecb9e1a
feat: Add FCN_ResNet101 model (#34)
Jungtaxi Feb 11, 2024
20aaf7e
refactor: Refactor trainer config (#36)
rudeuns Feb 11, 2024
4c5d9b1
feat: Add SMP models (#37)
Jungtaxi Feb 11, 2024
a23df34
feat: adopted new dataset (#39)
rsl82 Feb 13, 2024
074bcdf
refactor: Refactor dataset code (#43)
rsl82 Feb 13, 2024
53ef936
feat: Add inference (#47)
Jungtaxi Feb 13, 2024
48c7fc8
fix: Fix save logic (#46)
rudeuns Feb 13, 2024
4e9cf98
fix: Revert label structure (#49)
rsl82 Feb 14, 2024
d08c167
feat: Add transforms in config (#53)
rudeuns Feb 15, 2024
eb98559
refactor: Refactor inference (#52)
Jungtaxi Feb 15, 2024
20f08c9
fix: Fix use transform (#56)
Jungtaxi Feb 15, 2024
93a2f8b
feat: Add gradcam with streamlit (#45)
jinjero Feb 15, 2024
e743e3e
feat: Add visualize streamlit (#60)
ChoeHyeonWoo Feb 16, 2024
80729fb
feat: Add mixup trainer (#58)
Jungtaxi Feb 16, 2024
bb94593
feat: Add mmsegmentation model (#62)
ChoeHyeonWoo Feb 17, 2024
5330637
feat: Add preprocessing for fast training (#64)
rudeuns Feb 17, 2024
5d88a4f
feat: Add fine-tuning mode (#66)
rudeuns Feb 19, 2024
3e56cbd
feat: Add loss, model for experiment (#68)
rsl82 Feb 19, 2024
9f2ae33
feat: Add smp models (#74)
rudeuns Feb 25, 2024
fcca367
feat: Add pseudo labeling (#75)
rudeuns Feb 25, 2024
fec9115
feat: Add soft voting ensemble (#76)
rudeuns Feb 25, 2024
7cae238
feat: Add ensemble code (#70)
jinjero Feb 26, 2024
d51e24a
feat: Add super resolution (#78)
Jungtaxi Feb 26, 2024
42f5f3b
feat: Add multiprocessing in soft voting (#80)
Jungtaxi Feb 26, 2024
40d5c9f
feat: Add csv visulize (#82)
ChoeHyeonWoo Feb 27, 2024
46a2d56
feat: Add validation ensemble (#84)
ChoeHyeonWoo Feb 27, 2024
b97d8b8
feat: Add validation (#86)
ChoeHyeonWoo Feb 27, 2024
6d2dd6f
docs: Add readme
ChoeHyeonWoo Mar 3, 2024
1e64fa8
docs: Add readme (#88)
ChoeHyeonWoo Mar 3, 2024
c7a5fb3
docs: Update readme
ChoeHyeonWoo Mar 3, 2024
d1cf104
docs: Update readme
ChoeHyeonWoo Mar 3, 2024
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
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Feature request
about: 새로운 기능을 추가할 때 사용하는 템플릿
title: "[FEAT] "
labels: ''
assignees: 'username'

---
## Background
-

## To do
- [ ]
16 changes: 16 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## PR Type
- [ ] 기능 추가
- [ ] 기능 삭제
- [ ] 버그 수정
- [ ] 의존성, 환경 변수, 빌드 관련 코드 업데이트


## Change Log
-

## To Reviewer
-

## Issue Tags
- Closed: #
- See also: #
115 changes: 115 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# input data, saved log, checkpoints
data/
input/
saved/
datasets/

# editor, os cache directory
.vscode/
.idea/
__MACOSX/

wandb/
result/
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: check-json

- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
args: ["-l", "79"]
name: black
description: "Black: The uncompromising Python code formatter"
entry: black
language: python
minimum_pre_commit_version: 2.9.2
require_serial: true
types_or: [python, pyi]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.1.14'
hooks:
- id: ruff
args: [--ignore, F403]
162 changes: 162 additions & 0 deletions EDA/gradcam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')

import os
import sys
import torch
import numpy as np
import streamlit as st
from PIL import Image

from pytorch_grad_cam import GradCAM
from pytorch_grad_cam.utils.image import show_cam_on_image

sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
from util import CLASSES, CLASS2IND
from model import Unet, Linknet, FPN, PSPNet, PAN, FCN_ResNet50, FCN_ResNet101


IMAGE_ROOT = "/data/ephemeral/home/datasets/test/DCM"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")


class SemanticSegmentationTarget:
def __init__(self, category, mask):
self.category = category
self.mask = torch.from_numpy(mask)
self.mask = self.mask.to(device)

def __call__(self, model_output):
return (model_output[self.category, :, : ] * self.mask).sum()


def model_load(model_name, model_path):
if model_path.endswith('.pt'):
model = torch.load(model_path)
elif model_path.endswith('.pth'):
model = model_name
model_path = torch.load(model_path)
model = model.load_state_dict(model_path)
else:
st.warning("잘못된 확장자명이 입력되었습니다. .pt 또는 .pth 확장자를 사용해 주세요.")
model = None

return model


def gradcam(model, target_layers, index, image_path, hand):
path = os.path.join(image_path, hand)

image = Image.open(path).convert('RGB')
image = image.resize((512,512))
image = np.array(image)

rgb_img = np.float32(image) / 255

img = rgb_img.transpose(2, 0, 1)
img = torch.from_numpy(img).float()
img = torch.Tensor(img)
img = img.unsqueeze(0)

model = model.to(device)
input_tensor = img.to(device)

output = model(input_tensor)

normalized_masks = torch.nn.functional.softmax(output, dim=1).cpu()
mask = normalized_masks[0, :, :, :].argmax(axis=0).detach().cpu().numpy()
mask_float = np.float32(mask==index)

target = [SemanticSegmentationTarget(index, mask_float)]

with GradCAM(model=model,
target_layers=target_layers,) as cam:
grayscale_cam = cam(input_tensor=input_tensor, targets=target)[0,:]
cam_image = show_cam_on_image(rgb_img, grayscale_cam, use_rgb=True)

return cam_image


def main():
st.set_page_config(
page_title = "GradCAM",
page_icon="📷",
layout = "wide",
)

st.title("˙✧˖°📷 ༘ ⋆。°")
st.markdown("<hr style='margin-top: 0; margin-bottom: 0; height: 1px; border: 1px solid #635985;'><br>", True)

images = {
os.path.relpath(os.path.join(root, fname), start=IMAGE_ROOT)
for root, _dirs, files in os.walk(IMAGE_ROOT)
for fname in files
if os.path.splitext(fname)[1].lower() == ".png"
}

title = []
for i, im in enumerate(images):
title.append(im[:5])
title = list(set(title))
title = sorted(title)

model_name = Unet
model_path = '/data/ephemeral/home/save_dir/resnet34_unet_best_model_start100.pt'

model = model_load(model_name, model_path)
model = model.eval()

target_layers = [model.decoder.blocks[4].conv2]

img_name = st.selectbox("Image", title)
category = st.multiselect("Classes", CLASSES, default=CLASSES[0])

right_cam, left_cam = [], []
for cate in category:
index = CLASS2IND[cate]
image_path = os.path.join(IMAGE_ROOT, img_name)
image_file = os.listdir(image_path)

right = image_file[0]
left = image_file[1]

right = gradcam(model, target_layers, index, image_path, right)
left = gradcam(model, target_layers, index, image_path, left)

right_cam.append(right)
left_cam.append(left)


r_combined_cam = None
l_combined_cam = None

for cam in right_cam:
if r_combined_cam is None:
r_combined_cam = cam
else:
r_combined_cam = np.maximum(r_combined_cam, cam)

for cam in left_cam:
if l_combined_cam is None:
l_combined_cam = cam
else:
l_combined_cam = np.maximum(l_combined_cam, cam)

show_image_R = Image.fromarray(r_combined_cam)
show_image_L = Image.fromarray(l_combined_cam)


col1, col2 = st.columns(2)

with col1:
st.header("Right")
st.image(show_image_R)

with col2:
st.header("Left")
st.image(show_image_L)


if __name__ == "__main__":
main()
31 changes: 31 additions & 0 deletions EDA/pisiform.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ID001/image1661130828152_R.png 0.658682644367218
ID001/image1661130891365_L.png 0.8267679214477539
ID010/image1661145563354.png 0.8990980982780457
ID015/image1661216971933.png 0.767647922039032
ID015/image1661216998230.png 0.7194860577583313
ID021/image1661303624585.png 0.8322030901908875
ID027/image1661305195948.png 0.814268171787262
ID032/image1661317566170.png 0.8664231896400452
ID036/image1661318659827.png 0.7022705674171448
ID036/image1661318687383.png 0.7908452153205872
ID057/image1661391973543.png 0.865178644657135
ID075/image1661736898823.png 0.7843137383460999
ID077/image1661737137803.png 0.8726937174797058
ID082/image1661737564551.png 0.742072582244873
ID088/image1661821607947.png 0.8319395184516907
ID112/image1661907916373.png 0.8196896910667419
ID302/image1664241064255.png 0.8493593335151672
ID309/image1664241485928.png 0.3928753137588501
ID331/image1664847291816.png 0.8689588308334351
ID344/image1664932490676.png 0.828208863735199
ID374/image1665452614591.png 0.668241560459137
ID397/image1665538903963.png 0.8486701250076294
ID402/image1665539357117.png 0.8608115315437317
ID402/image1665539372545.png 0.8133237361907959
ID409/image1665540974169.png 0.8973684310913086
ID439/image1666141941646.png 0.8776015639305115
ID445/image1666144399306.png 0.8360981941223145
ID462/image1666575444051.png 0.8434149026870728
ID518/image1666749056245.png 0.8682605624198914
ID518/image1666749083578.png 0.8988138437271118
ID539/image1667266283922.png 0.8451685905456543
Loading