
2025.01.14
Chapter 03. Mask man classification
20. Mask man - 실습121. Mask man - 실습222. Mask man - 실습323. Mask man - 실습424. Mask man - Colab에서 돌려보기1) 세부적인 진행사항은 이전 과제 참조 (Mask Man 이론)
2) 아래의 내용은 실습과정에서 중요하거나, 필요한 사항만 기재.
OS모듈을 이용해서 폴더, 파일 목록 조회하는 방법


- 파일탐색에 있어서,
glob.glob()와os.listdir()명령어 차이



cv2.imread와plt.imshow()통해서 확인하기
import cv2
plt.figure(figsize=(15, 10))
for i in range(9):
random = np.random.randint(1, len(dataset_pd))
plt.subplot(3, 3, i+1)
plt.imshow(cv2.imread(dataset_pd.loc[random, 'image_path']))
plt.title(dataset_pd.loc[random, 'mask_status'])
plt.axis('off')
plt.show()


데이터를 [pixel값, 라벨 ( 0 or 1 )] 형태로 정리함.

사진확인 코드
fig, ax = plt.subplots(2, 3, figsize=(10, 6))
for row in range(2): # 0, 1
for col in range(3): # 0, 1, 2
image_index = row * 3 + col
# 0, 1, 2
# 100, 101, 102
ax[row, col].axis('off')
ax[row, col].imshow(data[image_index][0], cmap='gray')
if data[image_index][1] == 0: #Withoutmask
ax[row, col].set_title('Without Mask')
else:
ax[row, col].set_title('With Mask')

model = models.Sequential([
layers.Conv2D(32, kernel_size=(5,5), strides=(1,1),
padding='same', activation='relu', input_shape=(150, 150, 1)),
layers.MaxPooling2D(pool_size=(2,2), strides=(2,2)),
layers.Conv2D(64, kernel_size=(2,2), activation='relu', padding='same'),
layers.MaxPooling2D(pool_size=(2,2), strides=(2,2)),
layers.Dropout(0.25),
layers.Flatten(),
layers.Dense(1000, activation='relu'),
layers.Dense(1, activation='sigmoid')
])


