Workarounds in `keras_example.ipynb`
nicolefinnie opened this issue · comments
Hello Tobias,
I joined your hand-on session at PyConDE and I tried out your keras_example.ipynb
. And I hit the following errors, so I wanted to post the workarounds to be able to get your notebook to work.
- First, if you have a self certified server like myself, you might hit this issue during doing a handshake
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
Workaround is to bypass the error
#
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
- You might hit the error due to a change in
numpy.load()
innumpy=1.16.3
,allow_pickle
isFalse
by default.
ValueError: Object arrays cannot be loaded when allow_pickle=False
Workaround for numpy 1.16.3, see tensorflow issue 28102
import numpy as np
# Override np.load() function for keras.datasets.reuters.load_data()
# where np.load() is called
np_load_old = np.load
np.load = lambda *a, **k: np_load_old(*a, allow_pickle=True, **k)
print('Loading data...')
(x_train, y_train), (x_test, y_test) = reuters.load_data(num_words=max_words, test_split=0.2)
print(len(x_train), 'train sequences')
print(len(x_test), 'test sequences')
num_classes = np.max(y_train) + 1
print(num_classes, 'classes')
# restore np.load
np.load = np_load_old
# delete the temporary function object
del(np_load_old)