np.random.rand() 함수는 0부터 1 사이의 균일 분포에서 랜덤한 값을 생성합니다.
train_ratio를 0.9로 설정하면 약 90%의 확률로 훈련 데이터에 할당되고, 약 10%의 확률로 검증 데이터에 할당됩니다.
무작위로 값을 생성하기 때문에 실행할 때마다 실제로 할당되는 비율이 약간씩 다를 수 있습니다.
train_ratio = 0.9 # Set the desired ratio of training data
for label_name in label_names:
label_dir = os.path.join(root_dir, label_name)
files = os.listdir(label_dir)
np.random.shuffle(files) # Shuffle the files randomly
label_dir = os.path.join(root_dir, label_name)
files = os.listdir(label_dir)
np.random.shuffle(files) # Shuffle the files randomly
for i, file in enumerate(files):
if i < len(files) * train_ratio:
save_dir = os.path.join(train_dir, label_name)
else:
save_dir = os.path.join(val_dir, label_name)
if i < len(files) * train_ratio:
save_dir = os.path.join(train_dir, label_name)
else:
save_dir = os.path.join(val_dir, label_name)
이렇게 수정하는게 좀더 정확하게 할당됩니다. 참고 ~~
'Development > Python' 카테고리의 다른 글
| [오류 노트] Could not load library libcudnn_cnn_infer.so.8. Error: libcuda.so: cannot open shared object file: No such file or directory (0) | 2023.07.30 |
|---|---|
| Python Decorator(데코레이터) @의 의미 (0) | 2023.07.29 |
| toofoolab package list - 2023.07.16 (0) | 2023.07.16 |
| pytorch installation- cuda version(to-toofoolab) (0) | 2023.07.16 |
| requirements.txt(pip install -r requirements.txt)- to toofoolab (0) | 2023.07.16 |