卷积神经网络python代码
仅供学习参考使用
# -*- coding: utf-8 -*-
import numpy as np
class DataSet(object):
def __init__(self, images, labels, num_examples):
self._images = images
self._labels = labels
self._epochs_completed = 0 # 完成遍历轮数
self._index_in_epochs = 0 # 调用next_batch()函数后记住上一次位置
self._num_examples = num_examples # 训练样本数
def next_batch(self, batch_size, fake_data=False, shuffle=True):
start = self._index_in_epochs
if self._epochs_completed == 0 and start == 0 and shuffle:
index0 = np.arange(self._num_examples)
np.random.shuffle(index0)
self._images = np.array(self._images)[index0]
self._labels = np.array(self._labels)[index0]
if start + batch_size > self._num_examples:
self._epochs_completed += 1
rest_num_example