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


Python Net.getPrediction方法代碼示例

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


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

示例1: run_small_net

# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import getPrediction [as 別名]
def run_small_net():
    global training_data2, n2, t2, testing_data

    layers = []
    layers.append({'type': 'input', 'out_sx': 24, 'out_sy': 24, 'out_depth': 1})
    #layers.append({'type': 'fc', 'num_neurons': 50, 'activation': 'relu'})
    layers.append({'type': 'softmax', 'num_classes': 10})
    print 'Layers made...'

    n2 = Net(layers)
    print 'Smaller Net made...'
    print n2

    t2 = Trainer(n2, {'method': 'sgd', 'momentum': 0.0})
    print 'Trainer made for smaller net...'

    print 'In training of smaller net...'
    print 'k', 'time\t\t  ', 'loss\t  ', 'training accuracy'
    print '----------------------------------------------------'
    try:
        for x, y in training_data2: 
            stats = t2.train(x, y)
            print stats['k'], stats['time'], stats['loss'], stats['accuracy']
    except: #hit control-c or other
        pass

    print 'Testing smaller net: 5000 trials'
    right = 0
    count = 5000
    for x, y in sample(testing_data, count):
        n2.forward(x)
        right += n2.getPrediction() == y
    accuracy = float(right) / count * 100
    print accuracy
開發者ID:Aaronduino,項目名稱:ConvNetPy,代碼行數:36,代碼來源:dark_knowledge.py

示例2: run_big_net

# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import getPrediction [as 別名]
def run_big_net():
    global training_data, testing_data, n, t, training_data2

    training_data = load_data()
    testing_data = load_data(False)
    training_data2 = []

    print 'Data loaded...'

    layers = []
    layers.append({'type': 'input', 'out_sx': 24, 'out_sy': 24, 'out_depth': 1})
    layers.append({'type': 'fc', 'num_neurons': 100, 'activation': 'relu', 'drop_prob': 0.5})
    #layers.append({'type': 'fc', 'num_neurons': 800, 'activation': 'relu', 'drop_prob': 0.5})
    layers.append({'type': 'softmax', 'num_classes': 10})
    print 'Layers made...'

    n = Net(layers)
    print 'Net made...'
    print n

    t = Trainer(n, {'method': 'sgd', 'momentum': 0.0})
    print 'Trainer made...'

    print 'In training...'
    print 'k', 'time\t\t  ', 'loss\t  ', 'training accuracy'
    print '----------------------------------------------------'
    try:
        for x, y in training_data: 
            stats = t.train(x, y)
            print stats['k'], stats['time'], stats['loss'], stats['accuracy']
            training_data2.append((x, n.getPrediction()))
    except: #hit control-c or other
        pass

    print 'In testing: 5000 trials'
    right = 0
    count = 5000
    for x, y in sample(testing_data, count):
        n.forward(x)
        right += n.getPrediction() == y
    accuracy = float(right) / count * 100
    print accuracy
開發者ID:Aaronduino,項目名稱:ConvNetPy,代碼行數:44,代碼來源:dark_knowledge.py


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