inflearn logo
강의

講義

知識共有

深層学習CNN完璧ガイド - TFKerasバージョン

Xceptionモデル 学習後 Kaggleに 性能評価 csvファイル 提出

테스트 데이터셋 predict의 'NoneType' object has no attribute 'shape' 오류

解決済みの質問

405

cucury922

投稿した質問数 1

0

안녕하세요.

테스트 데이터셋을 predict하는 부분에서 오류가 나서 질문드립니다.

 

test_path = test_df['path'].values

test_ds = Plant_Dataset(image_filenames=test_path, labels=None, image_size=IMAGE_SIZE, batch_size=BATCH_SIZE, augmentor=None, shuffle=False, pre_func=xcp_preprocess_input)

preds = xcp_model_01.predict(test_ds)

 

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[40], line 7
      3 test_path = test_df['path'].values
      4 test_ds = Plant_Dataset(image_filenames=test_path, labels=None, image_size=IMAGE_SIZE, batch_size=BATCH_SIZE, 
      5                         augmentor=None, shuffle=False, pre_func=xcp_preprocess_input)
----> 7 preds = xcp_model_01.predict(test_ds)

File /opt/conda/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:123, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    120     filtered_tb = _process_traceback_frames(e.__traceback__)
    121     # To get the full stack trace, call:
    122     # `keras.config.disable_traceback_filtering()`
--> 123     raise e.with_traceback(filtered_tb) from None
    124 finally:
    125     del filtered_tb

File /opt/conda/lib/python3.10/site-packages/tree/__init__.py:435, in map_structure(func, *structures, **kwargs)
    432 for other in structures[1:]:
    433   assert_same_structure(structures[0], other, check_types=check_types)
    434 return unflatten_as(structures[0],
--> 435                     [func(*args) for args in zip(*map(flatten, structures))])

File /opt/conda/lib/python3.10/site-packages/tree/__init__.py:435, in <listcomp>(.0)
    432 for other in structures[1:]:
    433   assert_same_structure(structures[0], other, check_types=check_types)
    434 return unflatten_as(structures[0],
--> 435                     [func(*args) for args in zip(*map(flatten, structures))])

AttributeError: 'NoneType' object has no attribute 'shape'

 


test_image_batch, test_label_batch = next(iter(test_ds))

print(test_image_batch.shape, test_label_batch)
의 출력이
(32, 224, 224, 3) None

history.history['val_auc']
의 출력이
[0.9417113065719604, 0.9647012948989868, 0.9738287925720215, 0.9816075563430786, 0.9799161553382874, 0.9804703593254089, 0.9877450466156006, 0.9854006767272949, 0.9803326725959778, 0.9843235611915588]

학습도 완료됐고 Plant_Dataset도 제대로 작동하고 있습니다.

AttributeError:'NoneType' object has no attribute 'shape'으로 어느 부분이 문제가 되는지 질문드립니다.

 

머신러닝 딥러닝 keras tensorflow kaggle cnn

回答 1

1

dooleyz3525

안녕하십니까,

tensorflow가 버전업이 되면서 predict() 내에 들어가는 Dataset Sequence Class 로직이 달라져야 되는군요.

class Plant_Dataset(Sequence) 에서

def getitem(self, index): 함수에서 맨마지막의

return image_batch, label_batch 와 같이 적용하면 labels 인자값이 None이 들어오는 Test 데이터 세트의 경우 (image_batch, None) 이 tuple 형태로 반환되었는데, 이게 아니라 image_batch 만 명확하게 반환이 되어야 되는 것로 Tensorflow가 버전업이 되었습니다.

그래서 위 부분은 아래와 같이 변경 부탁드립니다.

if self.labels is None:

return image_batch

else:

return image_batch, label_batch

 

좋은 정보 감사합니다. 곧 전체 공지 하겠습니다.

resize 질문

0

50

1

20251212 Kaggle 런타임에 scikit-learn 설치 실패 트러블 슈팅

0

75

1

Loss와 매트릭 관계

0

61

2

Boston 코랩 실습

0

161

2

배치 정규화의 이해와 적용 2 강의 질문

0

134

2

Augmentation원본에 적용해서 데이터 갯수 자체를 늘리는 행위는 의미가있나요?

0

144

2

Conv함수 안에 activation 을 넣지 않는 이유가 뭔지 궁금합니다.

0

202

2

소프트맥스 관련 질문입니다

0

208

1

강의 관련 질문입니다

0

151

2

residual block과 identity block의 차이

0

184

2

옵티마이저와 경사하강법의 차이가 궁금합니다.

1

236

1

실습 환경

0

165

2

입력 이미지 크기

0

243

2

데이터 증강

0

194

2

albumentations ShiftScaleRotate

0

205

1

Model Input Size 관련

0

279

1

마지막에 bird -> frog 말고도 deer -> frog 도 잘못된것 아닌가요??

0

204

1

일반적인 질문 (kaggle notebook사용)

0

271

2

실무에서 Augmentation 적용 시

0

336

2

안녕하세요 교수님

0

231

1

가중치 초기화(Weight Initialization) 질문입니다.

0

324

1

학습이 이상하게 됩니다.

2

1032

2

boston import가 안됩니다

0

226

1

Boston 주택 가격에서, scailing 안하면 값이 발산합니다.

0

219

1