代码拉取完成,页面将自动刷新
import utils
from SDA_layers import StackedDA
def demo():
X,y = utils.load_mnist()
y = utils.makeMultiClass(y)
# building the SDA
sDA = StackedDA([100])
# pre-trainning the SDA
sDA.pre_train(X[:100], noise_rate=0.3, epochs=1)
# saving a PNG representation of the first layer
W = sDA.Layers[0].W.T[:, 1:]
utils.saveTiles(W, img_shape= (28,28), tile_shape=(10,10), filename="results/res_dA.png")
# adding the final layer
sDA.finalLayer(X[:37500], y[:37500], epochs=2)
# trainning the whole network
sDA.fine_tune(X[:37500], y[:37500], epochs=2)
# predicting using the SDA
pred = sDA.predict(X[37500:]).argmax(1)
# let's see how the network did
y = y[37500:].argmax(1)
e = 0.0
for i in range(len(y)):
e += y[i]==pred[i]
# printing the result, this structure should result in 80% accuracy
print "accuracy: %2.2f%%"%(100*e/len(y))
return sDA
if __name__ == '__main__':
demo()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。