Base on Tensorflow official quickstart, but to load train data locally(offline) instead of downloading online, avoid blocking by GFW in China or others.
Blocked by GFW(like China) can't download tensorflow.keras.datasets.*
by calling load_data()
methods.
keras.datasets | local_datasets |
---|---|
imdb.get_word_index | get_word_index |
imdb.load_data | load_data_imdb |
mnist.load_data | load_data_mnist |
fashion_mnist.load_data | load_data_fashion_mnist |
boston_housing.load_data | load_data_boston_housing |
Open notebook
in official_quickstart
.
copy utils
directory to any project.
from utils.local_datasets import load_data_fashion_mnist
(train_images, train_labels), (test_images, test_labels) = load_data_fashion_mnist()
import os
import sys
# add utils path to sys.path in order to import
# PS: be aware of the absolute path of utils
module_path = os.path.abspath(os.path.join('utils'))
if module_path not in sys.path:
sys.path.append(module_path)
from local_datasets import load_data_fashion_mnist
(train_images, train_labels), (test_images, test_labels) = load_data_fashion_mnist()