官术网_书友最值得收藏!

Building the network

Multiple deep learning frameworks have already implemented APIs for loading the F-MNIST dataset, including TensorFlow. For our implementation, we will be using Keras, another popular deep learning framework that is integrated with TensorFlow. The Keras datasets module provides a highly convenient interface for loading the datasets as numpy arrays.

Finally, we can start coding! For this exercise, we only need one Python module, which we will call cnn.py. Open up your favorite text editor or IDE, and let's get started.

Our first step is to declare the modules that we are going to use:

import logging
import os
import sys

logger = logging.getLogger(__name__)

import tensorflow as tf
import numpy as np
from keras.datasets import fashion_mnist
from keras.utils import np_utils

The following describes what each module is for and how we will use it:

 

We will implement our CNN as a class called SimpleCNN. The __init__ constructor takes a number of parameters:

class SimpleCNN(object):

def __init__(self, learning_rate, num_epochs, beta, batch_size):
self.learning_rate = learning_rate
self.num_epochs = num_epochs
self.beta = beta
self.batch_size = batch_size
self.save_dir = "saves"
self.logs_dir = "logs"
os.makedirs(self.save_dir, exist_ok=True)
os.makedirs(self.logs_dir, exist_ok=True)
self.save_path = os.path.join(self.save_dir, "simple_cnn")
self.logs_path = os.path.join(self.logs_dir, "simple_cnn")

The parameters our SimpleCNN is initialized with are described here:

 

Moreover, save_dir and save_path refer to the locations where we will store our network's parameters. logs_dir and logs_path refer to the locations where the statistics of the training run will be stored (we will show how we can retrieve these logs later).

主站蜘蛛池模板: 通许县| 林口县| 青岛市| 湘潭县| 冷水江市| 九龙县| 青神县| 中牟县| 樟树市| 德清县| 行唐县| 陇南市| 玉田县| 敦煌市| 大关县| 诸城市| 鄂尔多斯市| 江门市| 鄂托克前旗| 安新县| 石棉县| 营口市| 南汇区| 富民县| 抚顺市| 鹤庆县| 博客| 深圳市| 大兴区| 茌平县| 思茅市| 九龙城区| 克山县| 涟源市| 富蕴县| 武安市| 西丰县| 从化市| 凤冈县| 筠连县| 曲阜市|