Potato
μ•ˆλ…•ν•˜μ„Έμš”, κ°μž‘λ‹ˆλ‹€?πŸ₯” ^___^ 😺 github λ°”λ‘œκ°€κΈ° πŸ‘‰πŸ»

AI study/λ”₯λŸ¬λ‹ ν”„λ ˆμž„μ›Œν¬

[tensorflow] imdb.load_data 였λ₯˜ ν•΄κ²° - Object arrays cannot be loaded when allow_pickle=False

감자 πŸ₯” 2021. 3. 2. 16:39
λ°˜μ‘ν˜•

didu-story.tistory.com/25?category=903386

 

[tensorflow] ν…μŠ€νŠΈ λΆ„λ₯˜ (Text Classification) - IMDB

μ‹œμž‘ν•˜λ©° TF certification 을 μ·¨λ“ν•˜κΈ° μœ„ν•΄ νŠœν† λ¦¬μ–ΌλΆ€ν„° 곡뢀쀑이닀. μ˜ˆμƒλ³΄λ‹€ 였랜 μ‹œκ°„μ΄ 걸릴 것같닀 .. κ·Έλž˜λ„ μ΅œλŒ€ν•œ 단기간에 μ·¨λ“ν•˜λŠ”κ²ƒμ„ λͺ©ν‘œλ‘œ ν•œλ‹€!!!!!! ν™”μ΄νŒ… λ³Έ ν¬μŠ€νŒ…μ—μ„œλŠ” ν…μŠ€

didu-story.tistory.com

μœ„ ν¬μŠ€νŒ…μ„ μ§„ν–‰ν•˜λ˜ 쀑 데이터셋을 λ‹€μš΄λ‘œλ“œ ν•˜λŠ” κ³Όμ •μ—μ„œ μ•„λž˜μ™€ 같은 였λ₯˜κ°€ λ°œμƒν–ˆλ‹€.

from keras.datasets import imdb
(train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
# 좜λ ₯κ²°κ³Ό error
Object arrays cannot be loaded when allow_pickle=False

pycharmμ—μ„œ μ½”λ“œλ₯Ό μ‹€ν–‰ν–ˆμ„λ•ŒλŠ” 문제 μ—†μ—ˆμ§€λ§Œ, jupyter μ—μ„œ μ‹€ν–‰ν•˜λ‹ˆ 였λ₯˜κ°€ λ–΄λ‹€.

인터넷을 μ°Ύμ•„λ³΄λ‹ˆ 였λ₯˜κ°€ μ‘΄μž¬ν–ˆκ³ , κ·Έ 원인은... μ •ν™•νžˆ λͺ¨λ₯΄κ² λ‹€ 사싀..
(μ•„μ‹œλŠ” λΆ„ λŒ“κΈ€λ‘œ μ•Œλ €μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€ γ… γ… )

κ·Έλž˜λ„ 해결방법은 μ°Ύμ•˜λ‹€.

해결방법

import numpy as np
# save np.load
np_load_old = np.load

# modify the default parameters of np.load
np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)

# call load_data with allow_pickle implicitly set to true
(train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)

# restore np.load for future normal usage
np.load = np_load_old

이 μ½”λ“œλ‘œ μ§„ν–‰ν•˜λ©΄ λ¬΄μ‚¬νžˆ 데이터 셋을 뢈러올 수 μžˆλ‹€! (κ²°κ³Όλ₯Ό 좜λ ₯해보면,,)

print("ν›ˆλ ¨ μƒ˜ν”Œ: {}, λ ˆμ΄λΈ” : {}".format(len(train_data), len(train_labels)))

# 좜λ ₯ κ²°κ³Ό ↓↓↓
# ν›ˆλ ¨ μƒ˜ν”Œ: 25000, λ ˆμ΄λΈ” : 25000

 

원인을 μ°Ύμ•„λ³΄λ‹ˆ numpy 버전 문제라고 ν•˜μ‹œλŠ” 뢄도 계셨닀. 근데 이게 μ •ν™•ν•œ μ›μΈμΈμ§€λŠ” λͺ¨λ₯΄κ² λ‹€.

pycharm numpy version : 1.20.0
anaconda (jupyter) numpy version = 1.19.5

numpy의 버젼이 λ‹€λ₯Έ 것을 λ³΄λ‹ˆ λ§žλŠ” 것 같기도...

 

어쨋든 imdb.load_data μ—μ„œ ν•΄λ‹Ή 였λ₯˜κ°€ 뜨면 μœ„ μ½”λ“œλ‘œ μž¬μ‹€ν–‰ν•΄λ³΄κΈΈ λ°”λž€λ‹€.

λ°˜μ‘ν˜•