當前位置: 首頁>>代碼示例>>Python>>正文


Python mnist_loader.load_data_wrapper方法代碼示例

本文整理匯總了Python中mnist_loader.load_data_wrapper方法的典型用法代碼示例。如果您正苦於以下問題:Python mnist_loader.load_data_wrapper方法的具體用法?Python mnist_loader.load_data_wrapper怎麽用?Python mnist_loader.load_data_wrapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mnist_loader的用法示例。


在下文中一共展示了mnist_loader.load_data_wrapper方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_network

# 需要導入模塊: import mnist_loader [as 別名]
# 或者: from mnist_loader import load_data_wrapper [as 別名]
def run_network(filename, num_epochs, training_set_size=1000, lmbda=0.0):
    """Train the network for ``num_epochs`` on ``training_set_size``
    images, and store the results in ``filename``.  Those results can
    later be used by ``make_plots``.  Note that the results are stored
    to disk in large part because it's convenient not to have to
    ``run_network`` each time we want to make a plot (it's slow).

    """
    # Make results more easily reproducible
    random.seed(12345678)
    np.random.seed(12345678)
    training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
    net = network2.Network([784, 30, 10], cost=network2.CrossEntropyCost())
    net.large_weight_initializer()
    test_cost, test_accuracy, training_cost, training_accuracy \
        = net.SGD(training_data[:training_set_size], num_epochs, 10, 0.5,
                  evaluation_data=test_data, lmbda = lmbda,
                  monitor_evaluation_cost=True, 
                  monitor_evaluation_accuracy=True, 
                  monitor_training_cost=True, 
                  monitor_training_accuracy=True)
    f = open(filename, "w")
    json.dump([test_cost, test_accuracy, training_cost, training_accuracy], f)
    f.close() 
開發者ID:skylook,項目名稱:neural-networks-and-deep-learning,代碼行數:26,代碼來源:overfitting.py

示例2: run_networks

# 需要導入模塊: import mnist_loader [as 別名]
# 或者: from mnist_loader import load_data_wrapper [as 別名]
def run_networks():
    """Train networks using three different values for the learning rate,
    and store the cost curves in the file ``multiple_eta.json``, where
    they can later be used by ``make_plot``.

    """
    # Make results more easily reproducible
    random.seed(12345678)
    np.random.seed(12345678)
    training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
    results = []
    for eta in LEARNING_RATES:
        print "\nTrain a network using eta = "+str(eta)
        net = network2.Network([784, 30, 10])
        results.append(
            net.SGD(training_data, NUM_EPOCHS, 10, eta, lmbda=5.0,
                    evaluation_data=validation_data, 
                    monitor_training_cost=True))
    f = open("multiple_eta.json", "w")
    json.dump(results, f)
    f.close() 
開發者ID:skylook,項目名稱:neural-networks-and-deep-learning,代碼行數:23,代碼來源:multiple_eta.py

示例3: run_networks

# 需要導入模塊: import mnist_loader [as 別名]
# 或者: from mnist_loader import load_data_wrapper [as 別名]
def run_networks():
    # Make results more easily reproducible
    random.seed(12345678)
    np.random.seed(12345678)
    training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
    net = network2.Network([784, 30, 10], cost=network2.CrossEntropyCost())
    accuracies = []
    for size in SIZES:
        print "\n\nTraining network with data set size %s" % size
        net.large_weight_initializer()
        num_epochs = 1500000 / size 
        net.SGD(training_data[:size], num_epochs, 10, 0.5, lmbda = size*0.0001)
        accuracy = net.accuracy(validation_data) / 100.0
        print "Accuracy was %s percent" % accuracy
        accuracies.append(accuracy)
    f = open("more_data.json", "w")
    json.dump(accuracies, f)
    f.close() 
開發者ID:skylook,項目名稱:neural-networks-and-deep-learning,代碼行數:20,代碼來源:more_data.py

示例4: train

# 需要導入模塊: import mnist_loader [as 別名]
# 或者: from mnist_loader import load_data_wrapper [as 別名]
def train(self):
        # get hyper parameters
        epochs = self.hyperparas.get('epochs', 30)
        batch_size = self.hyperparas.get('batch_size', 10)
        eta = self.hyperparas.get('eta', 1.0)
        # get data
        cwd = os.getcwd()
        os.chdir(NNDL_PATH)
        training_data, validation_data, test_data = load_data_wrapper()
        os.chdir(cwd)
        return self.model.SGD(training_data, epochs, batch_size, eta, test_data) 
開發者ID:turiphro,項目名稱:deeplearning,代碼行數:13,代碼來源:neuralnets.py

示例5: run_network

# 需要導入模塊: import mnist_loader [as 別名]
# 或者: from mnist_loader import load_data_wrapper [as 別名]
def run_network(filename, n, eta):
    """Train the network using both the default and the large starting
    weights.  Store the results in the file with name ``filename``,
    where they can later be used by ``make_plots``.

    """
    # Make results more easily reproducible
    random.seed(12345678)
    np.random.seed(12345678)
    training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
    net = network2.Network([784, n, 10], cost=network2.CrossEntropyCost)
    print "Train the network using the default starting weights."
    default_vc, default_va, default_tc, default_ta \
        = net.SGD(training_data, 30, 10, eta, lmbda=5.0,
                  evaluation_data=validation_data, 
                  monitor_evaluation_accuracy=True)
    print "Train the network using the large starting weights."
    net.large_weight_initializer()
    large_vc, large_va, large_tc, large_ta \
        = net.SGD(training_data, 30, 10, eta, lmbda=5.0,
                  evaluation_data=validation_data, 
                  monitor_evaluation_accuracy=True)
    f = open(filename, "w")
    json.dump({"default_weight_initialization":
               [default_vc, default_va, default_tc, default_ta],
               "large_weight_initialization":
               [large_vc, large_va, large_tc, large_ta]}, 
              f)
    f.close() 
開發者ID:skylook,項目名稱:neural-networks-and-deep-learning,代碼行數:31,代碼來源:weight_initialization.py

示例6: main

# 需要導入模塊: import mnist_loader [as 別名]
# 或者: from mnist_loader import load_data_wrapper [as 別名]
def main():
    # Load the data
    full_td, _, _ = mnist_loader.load_data_wrapper()
    td = full_td[:1000] # Just use the first 1000 items of training data
    epochs = 500 # Number of epochs to train for

    print "\nTwo hidden layers:"
    net = network2.Network([784, 30, 30, 10])
    initial_norms(td, net)
    abbreviated_gradient = [
        ag[:6] for ag in get_average_gradient(net, td)[:-1]] 
    print "Saving the averaged gradient for the top six neurons in each "+\
        "layer.\nWARNING: This will affect the look of the book, so be "+\
        "sure to check the\nrelevant material (early chapter 5)."
    f = open("initial_gradient.json", "w")
    json.dump(abbreviated_gradient, f)
    f.close()
    shutil.copy("initial_gradient.json", "../../js/initial_gradient.json")
    training(td, net, epochs, "norms_during_training_2_layers.json")
    plot_training(
        epochs, "norms_during_training_2_layers.json", 2)

    print "\nThree hidden layers:"
    net = network2.Network([784, 30, 30, 30, 10])
    initial_norms(td, net)
    training(td, net, epochs, "norms_during_training_3_layers.json")
    plot_training(
        epochs, "norms_during_training_3_layers.json", 3)

    print "\nFour hidden layers:"
    net = network2.Network([784, 30, 30, 30, 30, 10])
    initial_norms(td, net)
    training(td, net, epochs, 
             "norms_during_training_4_layers.json")
    plot_training(
        epochs, "norms_during_training_4_layers.json", 4) 
開發者ID:skylook,項目名稱:neural-networks-and-deep-learning,代碼行數:38,代碼來源:generate_gradient.py


注:本文中的mnist_loader.load_data_wrapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。