Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 136 commits into
base: feedback
Choose a base branch
from
Open

Feedback #1

wants to merge 136 commits into from

Conversation

github-classroom[bot]
Copy link

@github-classroom github-classroom bot commented Nov 8, 2024

👋! GitHub Classroom created this pull request as a place for your teacher to leave feedback on your work. It will update automatically. Don’t close or merge this pull request, unless you’re instructed to do so by your teacher.
In this pull request, your teacher can leave comments and feedback on your code. Click the Subscribe button to be notified if that happens.
Click the Files changed or Commits tab to see all of the changes pushed to the default branch since the assignment started. Your teacher can see this too.

Notes for teachers

Use this PR to leave feedback. Here are some tips:

  • Click the Files changed tab to see all of the changes pushed to the default branch since the assignment started. To leave comments on specific lines of code, put your cursor over a line of code and click the blue + (plus sign). To learn more about comments, read “Commenting on a pull request”.
  • Click the Commits tab to see the commits pushed to the default branch. Click a commit to see specific changes.
  • If you turned on autograding, then click the Checks tab to see the results.
  • This page is an overview. It shows commits, line comments, and general comments. You can leave a general comment below.
    For more information about this pull request, read “Leaving assignment feedback in GitHub”.

Subscribed: @minrongtic @june21a @wonjeongjeong @Soy17 @Yoon0717 @sejongmin

github-classroom bot and others added 30 commits November 8, 2024 10:00
[Feature] : pull request template update
[Feature] : Issue Template/gitignore update
add refactored baseline code(torchvision)
june21a and others added 29 commits November 29, 2024 09:42
[Feature]:add code for morphology post process
- 대회 정책에 위반되지 않도록 X-ray image 제거
- 프로젝트 구조 추가
- train, inference 사용 방법 추가
project structure 수정
Final merge to main from develop branch
import pandas as pd
import os

### 아래 세 개의 경로 맞는지 확인해주세요 !!! ###
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os 에 상관 없이, 경로를 사용하려면 경로 관련 library 로 pathlib 사용을 추천드립니다.

from patlib import Path
excel_file = Path("meta_data.xlsx")
assert excel_file.exists(), "Invalid Excel file". # check dir is correct

ids_to_update = list(range(274, 320)) + [321]

# 폴더 이름에서 숫자 부분 추출 및 -1 인덱스 처리
indices_to_update_train = [int(folder[2:]) - 1 for folder in existing_folders]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID로 시작하는 3글자의 숫자를 찾는다면 아래와 같이 regex 를 활용해도 좋습니다!

pattern = re.compile(r"^ID\d{3}$")
test_dir_path = Path(TEST_DIR)
existing_folders = [f.name for f in test_dir_path.iterdir() if f.is_dir() and pattern.match(f.name)]


pngs = {
os.path.relpath(os.path.join(root, fname), start=args.src_image_path)
for root, _dirs, files in os.walk(args.src_image_path)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 변수는 _ 처리 하는게 가독성 측면에서 좋을 것 같습니다

Suggested change
for root, _dirs, files in os.walk(args.src_image_path)
for root, _, files in os.walk(args.src_image_path)

def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('--config_path', help='config의 경로', default='./configs/_baseline_/config_for_this_example.py')
parser.add_argument('--checkpoint_path', help='.pth파일 위치', default='./work_dir/best_mDice_iter_20000.pth')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

만약 항상 work_dir 안에 checkpoint_path 가 존재한다면, checkpoint_path 변수 하나만 입력으로 받아도 될 것 같습니다.

parser.add_argument('--config', type=str, default='config.yaml')
args = parser.parse_args()

with open(args.config, 'r') as f:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 config 를 parasing 하는 logic 은 main 함수 안에 있어도 될 것 같습니다.

train(model, train_loader, valid_loader, criterion, optimizer, scheduler, cfg)

sched = SchedulerSelector(cfg.scheduler, optimizer, cfg.max_epoch)
scheduler = sched.get_sched()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scheduler 가 train 에 입력된 이후 선언되는 것 같은데, 동작하는 코드인지 확인이 필요합니다!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wandb_train.py 와 train.py 가 wandb logger 를 사용하는 것 외에 크게 다른 부분은 없어보입니다! 하나로 통합되도 좋을 것 같습니다.

import streamlit as st
from PIL import Image

def rle2mask(rle, shape):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visualize_rle 의 rle2maks 와 중복되는 것 같습니다! 하나만 있어도 될 것 같습니다

Comment on lines +29 to +43
image_path_list = {
os.path.relpath(os.path.join(root, fname), start=info['image_root'].format(mode))
for root, _dirs, files in os.walk(info['image_root'].format(mode))
for fname in files
if os.path.splitext(fname)[1].lower() == ".png"
}
image_path_list = sorted(image_path_list)
if mode == 'train':
label_path_list = {
os.path.relpath(os.path.join(root, fname), start=info['label_root'])
for root, _dirs, files in os.walk(info['label_root'])
for fname in files
if os.path.splitext(fname)[1].lower() == ".json"
}
label_path_list = sorted(label_path_list)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 로직은 위에 load 함수에서 images, labels 를 구성하는 것과 동일해 보입니다. 함수화 하면 중복 코드를 줄일 수 있을 것 같습니다!

else:
print(f"No Exist '{folder_path}'")

def change_label_ID058():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label id 마다 함수를 작성하는 것 보단, id 를 입력 받고 변경하려는 value 를 입력 받는게 더 좋지 않을 까 싶습니다

Suggested change
def change_label_ID058():
import os
import json
import shutil
# Constants for file paths
ID058_FILE_PATH = "/data/ephemeral/home/data_v1/train/outputs_json/ID058/image1661392103627.json"
ID089_FILE_PATH = "/data/ephemeral/home/data_v1/train/outputs_json/ID089/image1661821711879.json"
# Label mappings
ID058_LABEL_MAP = {
'finger1': 'finger3',
'finger3': 'finger1',
'Trapezium': 'Hamate',
'Hamate': 'Trapezium',
'Trapezoid': 'Capitate',
'Capitate': 'Trapezoid',
'Pisiform': 'Scaphoid',
'Scaphoid': 'Triquetrum',
'Triquetrum': 'Lunate',
'Lunate': 'Pisiform',
'Radius': 'Ulna',
'Ulna': 'Radius'
}
ID089_LABEL_MAP = {
'Trapezium': 'Trapezoid',
'Trapezoid': 'Trapezium'
}
def delete_folder(folder_path):
"""Delete a folder if it exists."""
if os.path.exists(folder_path):
shutil.rmtree(folder_path)
print(f"Deleted '{folder_path}'")
else:
print(f"Folder does not exist: '{folder_path}'")
def change_labels(file_path, label_map):
"""Change labels in a JSON file based on a mapping."""
try:
with open(file_path, 'r') as file:
data = json.load(file)
for annotation in data.get('annotations', []):
if annotation['label'] in label_map:
annotation['label'] = label_map[annotation['label']] + '_'
# Remove trailing underscores
for annotation in data.get('annotations', []):
if annotation['label'][-1] == '_':
annotation['label'] = annotation['label'][:-1]
with open(file_path, 'w') as file:
json.dump(data, file, indent=4)
print(f"Edited '{file_path}'")
except Exception as e:
print(f"Error processing file '{file_path}': {e}")
if __name__ == "__main__":
# ID363: Delete folders
delete_folder("/data/ephemeral/home/data_v1/train/DCM/ID363")
delete_folder("/data/ephemeral/home/data_v1/train/outputs_json/ID363")
# ID487: Delete folders
delete_folder("/data/ephemeral/home/data_v1/train/DCM/ID487")
delete_folder("/data/ephemeral/home/data_v1/train/outputs_json/ID487")
# ID058: Change labels
change_labels(ID058_FILE_PATH, ID058_LABEL_MAP)
# ID089: Change labels (uncomment if needed)
# change_labels(ID089_FILE_PATH, ID089_LABEL_MAP)
# delete_folder("/data/ephemeral/home/data_v1/train/DCM/ID089")
# delete_folder("/data/ephemeral/home/data_v1/train/outputs_json/ID089")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants