티스토리 뷰
imdb.load_data() 호출 시 'Object arrays cannot be loaded when allow_pickle=False' 오류 수정하기
맨날치킨 2023. 1. 15. 16:05Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
How to fix 'Object arrays cannot be loaded when allow_pickle=False' for imdb.load_data() function?
imdb.load_data() 함수에 대해 'allow_pickle=False일 때 개체 배열을 로드할 수 없음'을 수정하는 방법은 무엇입니까?
문제 내용
I'm trying to implement the binary classification example using the IMDb dataset in Google Colab. I have implemented this model before. But when I tried to do it again after a few days, it returned a value error: 'Object arrays cannot be loaded when allow_pickle=False'
for the load_data() function.
Google Colab에서 IMDb 데이터 세트를 사용하여 이진 분류 예제를 구현하려고 합니다. 이전에 이 모델을 구현한 적이 있습니다. 하지만 며칠 후에 다시 시도하면 load_data() 함수에 대해 'allow_pickle=False일 때 개체 배열을 로드할 수 없습니다'라는 값 오류가 반환되었습니다.
I have already tried solving this, referring to an existing answer for a similar problem: How to fix 'Object arrays cannot be loaded when allow_pickle=False' in the sketch_rnn algorithm. But it turns out that just adding an allow_pickle argument isn't sufficient.
비슷한 문제에 대한 기존 답변을 참조하여 이미 해결을 시도했습니다: sketch_rnn 알고리즘에서 'allow_pickle=False일 때 객체 배열을 로드할 수 없음'을 수정하는 방법. 그러나 allow_pickle 인수를 추가하는 것만으로는 충분하지 않습니다.
My code:
제 코드:
from keras.datasets import imdb
(train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
The error:
오류:
ValueError Traceback (most recent call last)
<ipython-input-1-2ab3902db485> in <module>()
1 from keras.datasets import imdb
----> 2 (train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
2 frames
/usr/local/lib/python3.6/dist-packages/keras/datasets/imdb.py in load_data(path, num_words, skip_top, maxlen, seed, start_char, oov_char, index_from, **kwargs)
57 file_hash='599dadb1135973df5b59232a0e9a887c')
58 with np.load(path) as f:
---> 59 x_train, labels_train = f['x_train'], f['y_train']
60 x_test, labels_test = f['x_test'], f['y_test']
61
/usr/local/lib/python3.6/dist-packages/numpy/lib/npyio.py in __getitem__(self, key)
260 return format.read_array(bytes,
261 allow_pickle=self.allow_pickle,
--> 262 pickle_kwargs=self.pickle_kwargs)
263 else:
264 return self.zip.read(key)
/usr/local/lib/python3.6/dist-packages/numpy/lib/format.py in read_array(fp, allow_pickle, pickle_kwargs)
690 # The array contained Python objects. We need to unpickle the data.
691 if not allow_pickle:
--> 692 raise ValueError("Object arrays cannot be loaded when "
693 "allow_pickle=False")
694 if pickle_kwargs is None:
ValueError: Object arrays cannot be loaded when allow_pickle=False
높은 점수를 받은 Solution
Here's a trick to force imdb.load_data
to allow pickle by, in your notebook, replacing this line:
다음은 노트북에서 다음 행을 대체하여 imdb.load_data가 피클을 허용하도록 강제하는 요령입니다.
(train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
by this:
이를 통해:
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
가장 최근 달린 Solution
Use this
이것을 사용하세요
from tensorflow.keras.datasets import imdb
instead of this
이것 대신에
from keras.datasets import imdb
출처 : https://stackoverflow.com/questions/55890813/how-to-fix-object-arrays-cannot-be-loaded-when-allow-pickle-false-for-imdb-loa
'개발 > 파이썬' 카테고리의 다른 글
Python dictionary를 dataframe으로 변환하는 방법 (0) | 2023.01.16 |
---|---|
두 개의 딕셔너리 하나로 합치기(동일 키가 있을 경우에는 값을 더해서 합치기) (0) | 2023.01.15 |
'ImportError: no module named win32api' 수정하기 (0) | 2023.01.15 |
현재 파이썬 스크립트 파일의 이름 및 실행 중인 줄 번호 가져오기 (0) | 2023.01.15 |
리스트 앞에 값이나 리스트 추가하기 (0) | 2023.01.14 |