Load CIFAR-10 dataset. It consists of 60000 32x32 colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images. The dataset is divided into five training batches and one test batch, each with 10000 images. The test batch contains ex
(shape=(-1, 32, 32, 3), path='data', plotable=False)
| 520 | |
| 521 | |
| 522 | def load_cifar10_dataset(shape=(-1, 32, 32, 3), path='data', plotable=False): |
| 523 | """Load CIFAR-10 dataset. |
| 524 | |
| 525 | It consists of 60000 32x32 colour images in 10 classes, with |
| 526 | 6000 images per class. There are 50000 training images and 10000 test images. |
| 527 | |
| 528 | The dataset is divided into five training batches and one test batch, each with |
| 529 | 10000 images. The test batch contains exactly 1000 randomly-selected images from |
| 530 | each class. The training batches contain the remaining images in random order, |
| 531 | but some training batches may contain more images from one class than another. |
| 532 | Between them, the training batches contain exactly 5000 images from each class. |
| 533 | |
| 534 | Parameters |
| 535 | ---------- |
| 536 | shape : tupe |
| 537 | The shape of digit images e.g. (-1, 3, 32, 32) and (-1, 32, 32, 3). |
| 538 | path : str |
| 539 | The path that the data is downloaded to, defaults is ``data/cifar10/``. |
| 540 | plotable : boolean |
| 541 | Whether to plot some image examples, False as default. |
| 542 | |
| 543 | Examples |
| 544 | -------- |
| 545 | >>> X_train, y_train, X_test, y_test = tl.files.load_cifar10_dataset(shape=(-1, 32, 32, 3)) |
| 546 | |
| 547 | References |
| 548 | ---------- |
| 549 | - `CIFAR website <https://www.cs.toronto.edu/~kriz/cifar.html>`__ |
| 550 | - `Data download link <https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz>`__ |
| 551 | - `<https://teratail.com/questions/28932>`__ |
| 552 | |
| 553 | """ |
| 554 | path = os.path.join(path, 'cifar10') |
| 555 | logging.info("Load or Download cifar10 > {}".format(path)) |
| 556 | |
| 557 | # Helper function to unpickle the data |
| 558 | def unpickle(file): |
| 559 | fp = open(file, 'rb') |
| 560 | if sys.version_info.major == 2: |
| 561 | data = pickle.load(fp) |
| 562 | elif sys.version_info.major == 3: |
| 563 | data = pickle.load(fp, encoding='latin-1') |
| 564 | fp.close() |
| 565 | return data |
| 566 | |
| 567 | filename = 'cifar-10-python.tar.gz' |
| 568 | url = 'https://www.cs.toronto.edu/~kriz/' |
| 569 | # Download and uncompress file |
| 570 | maybe_download_and_extract(filename, path, url, extract=True) |
| 571 | |
| 572 | # Unpickle file and fill in data |
| 573 | X_train = None |
| 574 | y_train = [] |
| 575 | for i in range(1, 6): |
| 576 | data_dic = unpickle(os.path.join(path, 'cifar-10-batches-py/', "data_batch_{}".format(i))) |
| 577 | if i == 1: |
| 578 | X_train = data_dic['data'] |
| 579 | else: |
nothing calls this directly
no test coverage detected
searching dependent graphs…