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

train_model_reg.ipynb 에서 weight array selecting issue #1

Open
jsshinn opened this issue Sep 1, 2021 · 1 comment
Open

train_model_reg.ipynb 에서 weight array selecting issue #1

jsshinn opened this issue Sep 1, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@jsshinn
Copy link

jsshinn commented Sep 1, 2021

안녕하세요 승균님! 주간학습 피드백에도 적어놓긴 했는데, train_model_reg.ipynb 보다가 수정할 부분 있는 것 같아 issue로 남깁니다.
train_model_reg.ipynbWeightedRandomSampler 구하는 부분 (7번째 셀) 에서 다음과 같이 samples_weight 구하는 코드에서 에러가 나는 것 같습니다.

## prepare sampler

from torch.utils.data.sampler import WeightedRandomSampler

weight = df_train[target].value_counts().sort_index().to_numpy()
print('count :', weight)
weight = 1. / weight
samples_weight = np.array([weight[t] for t in df_train[target]])

weight = df_train[target].value_counts().sort_index().to_numpy() 로 만드시면서 numpy array로 변환 되는 것 같고, df_train[target] 를 for loop 돌리면서 나이 값인 tweight를 selecting 하시는 것 같습니다.
현재 상황에서는 weight array의 길이보다 나이 값이 클 경우, (55세, 60세 등) weight[60] 과 같이 select 할때 index error가 나는것 같습니다.
의도하시는게 target에 해당하는 나이 값에 해당하는 1 / 빈도수 값을 가져오시려고 하는 것 같은데, weight를 numpy array로 사용하면 나이 값에 대한 index를 갖지 않으므로, pandas series를 사용해서 나이 값을 Index로 가지고, 1 / 빈도수 값을 가지도록 만드시면 원하시는 동작이 될 것 같습니다.

아래 브랜치와 커밋내용에 해당하는 노트북 기준으로 확인했습니다.
https://github.com/boostcampaitech2/image-classification-level1-16/blob/493e0a666944e7cdbaa8079b3fce613a3a180e18/train_model_reg.ipynb

@jsshinn jsshinn added the bug Something isn't working label Sep 1, 2021
@jsg921019
Copy link
Contributor

jsg921019 commented Sep 1, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants