image_generator class개수 문제

5434 단어 tensorflowtensorflow
  • text와 image를 multimodal 할 일이 생겼다.
  • 그런데 text와 image label의 개수가 다른것이다..
  • 확인결과 text label개수는 339 image lbel은 338이였는데 image generator를 사용하면서 생긴 버그이다.

1) 잘못된 라벨 개수

train_generator = train_datagen.flow_from_dataframe(
        train_df,
        x_col='path',
        y_col='class_name',
        target_size=input_shape[:2],
        batch_size=batch_size,
        shuffle=False
)

validation_generator = test_datagen.flow_from_dataframe(
        test_df,
        x_col='path',
        y_col='class_name',
        target_size=input_shape[:2],
        batch_size=batch_size,
        shuffle=False
)
  • 출력
Found 11573 validated image filenames belonging to 338 classes.
Found 3076 validated image filenames belonging to 338 classes.

2) 수정

train_generator = train_datagen.flow_from_dataframe(
        train_df,
        x_col='path',
        y_col='class_name',
        target_size=input_shape[:2],
        batch_size=batch_size,
        shuffle=False,
        classes=list(train_df['class_name'])
)

validation_generator = test_datagen.flow_from_dataframe(
        test_df,
        x_col='path',
        y_col='class_name',
        target_size=input_shape[:2],
        batch_size=batch_size,
        shuffle=False,
        classes=list(train_df['class_name'])
)
  • 출력
Found 11573 validated image filenames belonging to 339 classes.
Found 3076 validated image filenames belonging to 339 classes.
  • classes 를 이용하여 직접 라벨수를 정해주면 된다.

좋은 웹페이지 즐겨찾기