―― Wie eingangs erwähnt, verweisen wir auf Folgendes. - https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/contrib/learn/python/learn/datasets/mnist.py
class DataSet():
"""Datensatzverwaltung."""
def __init__(self, images, labels):
self._num_examples = images.shape[0]
images = images.reshape(images.shape[0], images.shape[1] * images.shape[2])
images = images.astype(numpy.float32)
images = numpy.multiply(images, 1.0 / 255.0)
self._images = images
self._labels = labels
self._epochs_completed = 0
self._index_in_epoch = 0
def dense_to_one_hot(labels_dense, num_classes):
"""Convert class labels from scalars to one-hot vectors."""
num_labels = labels_dense.shape[0]
index_offset = numpy.arange(num_labels) * num_classes
labels_one_hot = numpy.zeros((num_labels, num_classes))
labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1
return labels_one_hot
--Laden Sie das Pickle-Bild und die Beschriftung in den obigen Datensatz.
def load_data(one_hot=False, validation_size=0):
"""Konfigurieren Sie den Datensatz.Lesen Sie nach py."""
train_num = AUGMENT_NUM if USE_AUGMENT else 0
datasets_file = os.path.join(DATASETS_PATH, ','.join(CLASSES), '{}x{}-{}.pickle'.format(IMG_ROWS, IMG_COLS, train_num))
with open(datasets_file, 'rb') as fin:
(train_images, train_labels), (test_images, test_labels) = pickle.load(fin)
if one_hot:
num_classes = len(numpy.unique(train_labels))
train_labels = dense_to_one_hot(train_labels, num_classes)
test_labels = dense_to_one_hot(test_labels, num_classes)
perm = numpy.arange(train_images.shape[0])
numpy.random.shuffle(perm)
train_images = train_images[perm]
train_labels = train_labels[perm]
validation_images = train_images[:validation_size]
validation_labels = train_labels[:validation_size]
train_images = train_images[validation_size:]
train_labels = train_labels[validation_size:]
train = DataSet(train_images, train_labels)
validation = DataSet(validation_images, validation_labels)
test = DataSet(test_images, test_labels)
return Datasets(train=train, validation=validation, test=test)
--Erstellt einen Dataset Loader. Die Originaldaten wurden geändert, um die "Pickle" -Daten zu lesen. ―― Heutzutage können Sie diesen Bereich jedoch ausblenden und programmieren, sodass Sie ihn kaum implementieren müssen. Ich denke, es ist das erste und das letzte. ――Nächstes Mal möchte ich ein Lernmodell erstellen.
Recommended Posts