In [2]:
%matplotlib inline

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

import theano.tensor as T
import theano
from itertools import izip
import random
from random import shuffle

讀取 Miku


In [3]:
img_count = 0
def showimg(img):
    muki_pr = np.zeros((500,500,3))
    l =img.tolist()
    count = 0
    for x in range(500):
        for y in range(500):
            muki_pr[y][x] = l[count]
            count += 1
    plt.imshow(muki_pr)
def saveimg(fname,img):
    muki_pr = np.zeros((500,500,3))
    l =img.tolist()
    count = 0
    for x in range(500):
        for y in range(500):
            muki_pr[y][x] = l[count]
            count += 1
    plt.imsave(fname,muki_pr)

In [4]:
def read_muki():
    img_data = np.random.randn(250000,1)
    xy_data = []
    import random

    f = open('./muki.txt','rb')
    count = 0
    for line in f:
        y,x,c = line.split()
        xy_data.append([float(x),float(y)])
        x = (float(x) )*100. + 250
        y = (float(y) )*100. + 250
        c = float(c)

        img_data[count] = c
        
        count = count + 1
    return np.matrix(xy_data),img_data

xy_data,img_data = read_muki()    
showimg(img_data)



In [5]:
print xy_data[:10]
print img_data[:10]


[[-2.5  -2.5 ]
 [-2.49 -2.5 ]
 [-2.48 -2.5 ]
 [-2.47 -2.5 ]
 [-2.46 -2.5 ]
 [-2.45 -2.5 ]
 [-2.44 -2.5 ]
 [-2.43 -2.5 ]
 [-2.42 -2.5 ]
 [-2.41 -2.5 ]]
[[ 0.]
 [ 0.]
 [ 0.]
 [ 0.]
 [ 0.]
 [ 0.]
 [ 0.]
 [ 0.]
 [ 0.]
 [ 0.]]

Muki NN


In [6]:
batch_size = 500
hidden_size = 128

In [7]:
x = T.matrix(name='x',dtype='float32') # size =2
y = T.matrix(name='x',dtype='float32') # size =1


w1 = theano.shared(np.random.randn(hidden_size,2))
b1 = theano.shared(np.random.randn(hidden_size))
w2 = theano.shared(np.random.randn(hidden_size,hidden_size))
b2 = theano.shared(np.random.randn(hidden_size))
w3 = theano.shared(np.random.randn(1,hidden_size))
b3 = theano.shared(np.random.randn(1))

第一層


In [8]:
z1 = T.dot(w1,x) + b1.dimshuffle(0,'x')
a1 = 1/(1+T.exp(-z1))

In [9]:
fa1 = theano.function(inputs=[x],outputs=[a1],allow_input_downcast=True)
l1_o= fa1(np.random.randn(2,batch_size))

In [10]:
l1_o= fa1(xy_data[:500].T)

第二層


In [11]:
z2 = T.dot(w2,a1) + b2.dimshuffle(0,'x')
a2 = 1/(1+T.exp(-z2))

In [12]:
fa2 = theano.function(inputs=[x],outputs=[a2],allow_input_downcast=True)

In [13]:
l2_o = fa2(np.random.randn(2,batch_size))

In [14]:
l2_o= fa2(xy_data[:500].T)
print l2_o[0].shape


(128, 500)

第三層


In [23]:
z3 = T.dot(w3,a2) + b3.dimshuffle(0,'x')
a3 = 1/(1+T.exp(-z3))

In [25]:
fa3 = theano.function(inputs=[x],outputs=[a3],allow_input_downcast=True)
l3_o = fa3(np.random.randn(2,batch_size))
print l3_o[0].shape


(1, 500)

定義 Cost Function & Update Function


In [26]:
y_hat = T.matrix('reference',dtype='float32')
cost = T.sum((a3-y_hat)**2)/batch_size

In [27]:
dw1,dw2,dw3,db1,db2,db3 = T.grad(cost,[w1,w2,w3,b1,b2,b3])

def Myupdates(ps,gs):
    from itertools import izip
 
    r = 0.5
    pu = [ (p,p-r*g) for p,g in izip(ps,gs)   ]
    return pu

In [29]:
train = theano.function(inputs=[x,y_hat],
                        outputs=[a3,cost],
                        updates=Myupdates([w1,w2,b1,b2,w3,b3],[dw1,dw2,db1,db2,dw3,db3]),
                        allow_input_downcast=True,)

Training


In [32]:
def training(xy_data,img_data):
    for ii in range(1000):
        for i in range(500):

            start = i * 500 
            end  = start + 500
            img_predict,cost_predict = train(xy_data[start:end].T,img_data[start:end].T)

        if ii % 5 == 0:
            saveimg('./imgs/muki_'+ str(ii) +'.png', fa3(xy_data.T)[0].T)
        print cost_predict,

In [33]:
training(xy_data,img_data)


1.95025705114e-06 2.17305620986e-06 1.68649787039e-06 1.25956621256e-06 8.63419856337e-07 5.36193522996e-07 3.2976588041e-07 2.27709812058e-07 1.71146762211e-07 1.29372600136e-07 9.70224315787e-08 7.19332561151e-08 5.33969605359e-08 3.94842035864e-08 2.93452456106e-08 2.2706561381e-08 2.77263643607e-08 1.30487686622e-08 8.1193881343e-09 5.54503369581e-09 3.94160746659e-09 3.10275060885e-09 5.92385737653e-09 9.13232364591e-09 4.58839133446e-09 3.17988513431e-09 2.76569571208e-09 2.25529108265e-09 1.7455524496e-09 1.31412305514e-09 1.41116310656e-09 1.31992483818e-09 8.81222642023e-10 7.35196671871e-10 6.32639109534e-10 5.32096145923e-10 4.43074278112e-10 3.74625767394e-10 3.21590162479e-10 2.73204757981e-10 2.35410635127e-10 1.99438092939e-10 1.67679160499e-10 1.42884842354e-10 1.24156837642e-10 1.09978463444e-10 9.91420297121e-11 9.13505727662e-11 8.60160060876e-11 1.10311324466e-10 8.93050013613e-11 9.53464509221e-11 8.93464127494e-11 8.68752848509e-11 8.80314791815e-11 9.09302438081e-11 9.43821751585e-11 1.006757707e-10 1.06115684556e-10 1.09694339866e-10 1.15184647821e-10 1.15649008284e-10 1.15678310065e-10 1.17818512101e-10 1.19401784286e-10 1.13258216983e-10 1.05631479552e-10 9.50369949039e-11 1.02879618396e-10 1.06795047806e-10 1.0124258255e-10 8.91088721864e-11 7.73957122434e-11 6.60683167607e-11 5.59853670848e-11 4.37812628393e-11 4.02549828525e-11 3.58036273314e-11 3.07817798521e-11 2.63314102086e-11 2.31080847455e-11 1.25327917149e-11 1.76673262779e-11 9.26497858183e-12 8.85621868407e-12 7.24487742639e-12 8.2896376938e-12 5.40520636064e-12 4.91300606204e-12 4.50769087509e-12 4.1458895534e-12 3.77746955242e-12 3.43940021978e-12 3.15018242923e-12 2.91026045085e-12 2.7097280334e-12 2.54152926608e-12 2.39996934458e-12 2.2811745914e-12 2.18206595837e-12 2.10328924908e-12 2.05381927416e-12 2.02094968856e-12 1.99903344736e-12 1.98470063999e-12 1.83290831246e-12 2.56865929558e-12 2.82790663396e-12 3.14376857904e-12 3.5734332868e-12 4.13327952673e-12 4.96873676006e-12 4.77497685854e-12 4.55949957169e-12 4.38245291551e-12 4.14678190289e-12 3.83399600819e-12 3.49639379699e-12 3.15853477661e-12 2.84224044911e-12 2.57621326874e-12 2.36725091608e-12 2.1477914967e-12 1.89143033597e-12 1.63907855757e-12 1.44764739085e-12 1.28687490713e-12 1.10856326012e-12 8.78323198627e-13 8.5617207778e-13 7.49165340071e-13 7.62113992184e-13 6.71634466925e-13 6.11920998971e-13 5.55016254135e-13 5.41213869246e-13 5.369961195e-13 3.33006300972e-13 2.93327339163e-13 2.42148416716e-13 2.19112416678e-13 1.98699548152e-13 1.77762147213e-13 1.58796552585e-13 1.42384297288e-13 1.27821697072e-13 1.14340938442e-13 1.0302356366e-13 9.29591257081e-14 8.11500792161e-14 7.36262467113e-14 6.32214786944e-14 5.78258738786e-14 5.01781362873e-14 4.76052901356e-14 3.98582727245e-14 3.61235260179e-14 3.20668650204e-14 2.85090273186e-14 2.55343378458e-14 2.29935215202e-14 2.0535075335e-14 1.89042073371e-14 1.85258971057e-14 1.8223441451e-14 1.75695925312e-14 1.72878720488e-14 1.55598893929e-14 1.37061647661e-14 1.13736663246e-14 9.97301773964e-15 9.0176895208e-15 8.29876980108e-15 8.27241891133e-15 8.00205146465e-15 8.67978050338e-15 9.21804349662e-15 9.82673029994e-15 1.02159440686e-14 1.05340290615e-14 1.06215945706e-14 1.1244842184e-14 1.20118924553e-14 1.31531253478e-14 1.4285059418e-14 1.52560817768e-14 1.59637127817e-14 1.5880109304e-14 1.73540672413e-14 1.79297049892e-14 1.91041866105e-14 1.96645474826e-14 2.03584485069e-14 2.09366862685e-14 2.15542648634e-14 2.19433228871e-14 2.08956559345e-14 2.16223153821e-14 2.20247023117e-14 2.23498176894e-14 2.26798967022e-14 2.2799654732e-14 2.22682823301e-14 2.20722695491e-14 2.27837271196e-14 2.26157101515e-14 2.33114383339e-14 2.36668970315e-14 2.4045032276e-14 2.39650848953e-14 2.55767567469e-14 2.58763139021e-14 2.64399160151e-14 2.68671562108e-14 2.72740807888e-14 2.76039814847e-14 2.78694175546e-14 2.80678437128e-14 2.81907370351e-14 2.82410033656e-14 2.81471913977e-14 2.7920552562e-14 2.77142249832e-14 2.70694844939e-14 2.50095192072e-14 2.49001348445e-14 2.41766144819e-14 2.36571259004e-14 2.26059671091e-14 2.36268503272e-14 2.34327709756e-14 2.32659935645e-14 2.34411588463e-14 2.33830958388e-14 2.35924852403e-14 2.35964404943e-14 2.34162408635e-14 2.31809225321e-14 2.28353876832e-14 2.24236241753e-14 2.19599816091e-14 2.14381490951e-14 2.08366344375e-14 2.03617186938e-14 1.91000612502e-14 1.91467379212e-14 1.86294394827e-14 1.86094717453e-14 1.8190422199e-14 1.74727693137e-14 1.89880270929e-14 1.78260128536e-14 1.90147357033e-14 1.80687969569e-14 1.89512911629e-14 1.80167905466e-14 1.83264748167e-14 1.73108999667e-14 1.72774677776e-14 1.67812320871e-14 1.67488708502e-14 1.64810616945e-14 1.63320780995e-14 1.60563189048e-14 1.58620854592e-14 1.55987331349e-14 1.53971208361e-14 1.51605353554e-14 1.49693439852e-14 1.47612249343e-14 1.45858636098e-14 1.44031144017e-14 1.42437933616e-14 1.40819560817e-14 1.39366424207e-14 1.37910009643e-14 1.3656693622e-14 1.3522769063e-14 1.33963422808e-14 1.32704071571e-14 1.31493784446e-14 1.30289372805e-14 1.2911910053e-14 1.27957328865e-14 1.26822279404e-14 1.25698797024e-14 1.24598216131e-14 1.23511199949e-14 1.22444316457e-14 1.21391348269e-14 1.20355648162e-14 1.19332628215e-14 1.18323494502e-14 1.17324457474e-14 1.16335263891e-14 1.15352455251e-14 1.14374762136e-14 1.13398825389e-14 1.12422706458e-14 1.11443142624e-14 1.10457951615e-14 1.09464299369e-14 1.08460498381e-14 1.07445007965e-14 1.06417910738e-14 1.0538034644e-14 1.04335438959e-14 1.03287075848e-14 1.02238547575e-14 1.01187966555e-14 1.00122199654e-14 9.90105827829e-15 9.78265600385e-15 9.65986164949e-15 9.53756004375e-15 9.4172503172e-15 9.29608630975e-15 9.17128314674e-15 9.04576890869e-15 8.9230605582e-15 8.80590833816e-15 8.69497768644e-15 8.5908914885e-15 8.49331646154e-15 8.40252988955e-15 8.31810873181e-15 8.24040534815e-15 8.16904182645e-15 8.10452579244e-15 8.04650305396e-15 7.99566978071e-15 7.9516060453e-15 7.91519722515e-15 7.88574104179e-15 7.86426256164e-15 7.84935430812e-15 7.84210507842e-15 7.83963979855e-15 7.84309336017e-15 7.84701055847e-15 7.85381970188e-15 7.85553158535e-15 7.86034434464e-15 7.85585510958e-15 7.86042043964e-15 7.84745555371e-15 7.85736768886e-15 7.8268354216e-15 7.85688531584e-15 7.7795355103e-15 7.87992206881e-15 7.6599910083e-15 7.87584045056e-15 7.35223508545e-15 8.12396387821e-15 6.71139602254e-15 1.01394686524e-14 6.14490295894e-15 8.44599271496e-15 6.7624466742e-15 1.03189677135e-14 5.97007859707e-15 8.39301139192e-15 6.68637000848e-15 1.13441721613e-14 6.05963312124e-15 8.11571577072e-15 7.66952460659e-15 9.12447865413e-15 6.56989429567e-15 1.08988942619e-14 6.30767199593e-15 9.78763897165e-15 6.56200309353e-15 1.08071118349e-14 6.45583913672e-15 1.0315729377e-14 6.7544724585e-15 1.07139633946e-14 6.45609365854e-15 1.04276781295e-14 6.40317053458e-15 1.06244623785e-14 6.28862150753e-15 1.02121724629e-14 6.22931716014e-15 1.0631448154e-14 6.12055864863e-15 9.87938743706e-15 6.09554699183e-15 1.16393110355e-14 6.1610713843e-15 7.19079529763e-15 1.36057806196e-14 4.94135043407e-15 1.69119375505e-14 7.07242351335e-15 6.39465846591e-15 7.73653066817e-15 1.19098614696e-14 5.26820636625e-15 1.62017703874e-14 9.55585689106e-15 6.04058303925e-15 6.89960142585e-15 1.44860163044e-14 8.25777170616e-15 6.81242118934e-15 1.45441843716e-14 9.11038176271e-15 7.58531168187e-15 6.97428727591e-15 1.44403242667e-14 9.00265338706e-15 7.79561242953e-15 6.39449865188e-15 1.24369251215e-14 7.51355940381e-15 5.66200722799e-15 1.21409705706e-14 8.00300087746e-15 7.39655662539e-15 5.67815882012e-15 5.52079450138e-15 9.98093696534e-15 4.39249367615e-15 9.17508802606e-15 6.03073708388e-15 4.54000093168e-15 4.78120241903e-15 8.83847901912e-15 5.48217394108e-15 4.61029248881e-15 3.77257002408e-15 7.79676176898e-15 4.75218454592e-15 3.58920267031e-15 3.79759426458e-15 6.65840852925e-15 3.44204161234e-15 3.03721091058e-15 4.71713721863e-15 2.76075237308e-15 4.13096527867e-15 2.7630847221e-15 5.16824771652e-15 3.68730145207e-15 3.92052080709e-15 4.17061496706e-15 4.1242678537e-15 4.02543349441e-15 4.02791059199e-15 4.03003790218e-15 4.07630774042e-15 4.11050717478e-15 4.16209480039e-15 4.19712093218e-15 4.23612098503e-15 4.25926327438e-15 4.28150047928e-15 4.29076910789e-15 4.29792258556e-15 4.29513793839e-15 4.29022052648e-15 4.27778078422e-15 4.2634403341e-15 4.24329436112e-15 4.22145934572e-15 4.19498251468e-15 4.166973305e-15 4.13511056886e-15 4.10184901791e-15 4.06529876084e-15 4.02751116118e-15 3.98690079733e-15 3.9453028801e-15 3.90134986927e-15 3.85680004386e-15 3.81041975169e-15 3.76397776137e-15 3.71625935949e-15 3.66908673998e-15 3.62112116123e-15 3.57428295527e-15 3.52696834445e-15 3.48129160406e-15 3.43524496666e-15 3.39130031367e-15 3.34686871272e-15 3.30502215824e-15 3.26232161491e-15 3.22279960951e-15 3.18174070648e-15 3.14469670284e-15 3.10498853141e-15 3.07058406169e-15 3.03171027673e-15 3.00022903457e-15 2.96137334495e-15 2.93339397125e-15 2.89326819164e-15 2.86994158057e-15 2.82643467471e-15 2.80993197578e-15 2.75947019201e-15 2.75357002146e-15 2.69030631455e-15 2.70020018954e-15 2.61732415825e-15 2.64402789259e-15 2.54821528382e-15 2.57727798597e-15 2.50023784747e-15 2.52382279109e-15 2.43248947631e-15 2.45426054292e-15 2.39138188759e-15 2.41085550751e-15 2.30776149011e-15 2.31745620326e-15 2.31203271604e-15 2.30005399635e-15 2.20757920412e-15 2.23368279036e-15 2.15554836007e-15 2.16587286152e-15 2.13411929988e-15 2.1468753328e-15 2.03020744878e-15 1.99098629907e-15 2.08286629855e-15 1.99463764837e-15 2.00555922663e-15 1.93257949197e-15 1.92194854954e-15 1.94925323145e-15 1.90765850705e-15 1.88335418778e-15 1.85957820665e-15 1.84244464589e-15 1.81641696036e-15 1.80925517748e-15 1.76821308677e-15 1.78287391611e-15 1.69982222557e-15 1.67244167285e-15 1.74779763694e-15 1.65200061881e-15 1.60504587384e-15 1.67629435968e-15 1.62937873813e-15 1.63823273135e-15 1.5399342967e-15 1.36046031949e-15 7.09636618315e-16 8.71699717001e-16 8.90736209066e-16 9.45008158813e-16 7.49180519109e-16 6.12428856229e-16 5.56684801216e-16 5.47780245362e-16 4.61053199638e-16 4.17109781982e-16 3.80298931872e-16 3.51444528515e-16 3.28541000905e-16 3.09984432828e-16 2.94984327796e-16 2.82800055193e-16 2.72905139889e-16 2.64871140829e-16 2.58354819377e-16 2.53080373855e-16 2.4882711804e-16 2.45420363748e-16 2.42723263408e-16 2.4062958164e-16 2.3905717081e-16 2.37942206498e-16 2.37234262805e-16 2.36892263926e-16 2.36881304522e-16 2.3717026412e-16 2.37730096314e-16 2.38532676672e-16 2.39550084369e-16 2.40754211097e-16 2.42116619897e-16 2.43608573399e-16 2.45201197687e-16 2.46865726792e-16 2.48573794691e-16 2.50297749037e-16 2.52010966359e-16 2.53688142937e-16 2.55305549732e-16 2.56841247857e-16 2.58275252444e-16 2.59589651028e-16 2.60768673169e-16 2.61798722243e-16 2.62668370641e-16 2.63368328349e-16 2.63891388633e-16 2.64232359909e-16 2.64387985341e-16 2.64356854581e-16 2.64139313889e-16 2.63737368465e-16 2.63154581219e-16 2.62395964474e-16 2.61467859101e-16 2.60377792209e-16 2.59134313266e-16 2.57746792331e-16 2.56225186199e-16 2.5457977251e-16 2.52820864464e-16 2.509585299e-16 2.49002341448e-16 2.46961182268e-16 2.44843125793e-16 2.42655396731e-16 2.40404403147e-16 2.38095824501e-16 2.35734734662e-16 2.33325736933e-16 2.3087309792e-16 2.283808646e-16 2.25852959881e-16 2.23293253547e-16 2.20705610148e-16 2.18093917548e-16 2.15462099075e-16 2.12814116647e-16 2.10153965709e-16 2.07485669459e-16 2.04813270937e-16 2.02140828526e-16 1.99472413523e-16 1.9681211388e-16 1.94164042611e-16 1.91532354615e-16 1.8892127272e-16 1.86335129352e-16 1.83778426771e-16 1.81255929791e-16 1.78772810127e-16 1.76334877001e-16 1.73948966666e-16 1.71623630653e-16 1.69370431568e-16 1.67206559406e-16 1.65160612322e-16 1.63286993345e-16 1.61708638147e-16 1.60787071451e-16 1.62515905362e-16 1.49258535435e-16 1.32319012067e-16 1.3051626386e-16 1.27020905742e-16 1.2259435759e-16 1.18510673703e-16 1.15036701524e-16 1.1220466502e-16 1.0996220513e-16 1.0821031637e-16 1.06846947622e-16 1.05786836427e-16 1.04965693811e-16 1.04337472748e-16 1.03869730639e-16 1.03539507413e-16 1.03330262162e-16 1.03229614314e-16 1.03227553628e-16 1.03314970457e-16 1.03482506124e-16 1.03719791565e-16 1.04015113197e-16 1.04355482922e-16 1.04727022222e-16 1.05115526978e-16 1.05507071608e-16 1.05888536995e-16 1.06247996263e-16 1.06574945927e-16 1.06860402645e-16 1.07096901165e-16 1.07278430155e-16 1.07400332465e-16 1.07459182293e-16 1.07452666503e-16 1.07379454749e-16 1.07239083546e-16 1.0703184724e-16 1.06758698698e-16 1.06421161947e-16 1.06021250982e-16 1.05561396369e-16 1.05044375819e-16 1.04473247721e-16 1.03851286954e-16 1.0318192217e-16 1.02468676676e-16 1.01715112029e-16 1.00924777001e-16 1.00101163466e-16 9.92476693457e-17 9.83675727556e-17 9.746401724e-17 9.65400118615e-17 9.55984452125e-17 9.46421267425e-17 9.36738479003e-17 9.2696485942e-17 9.17131618036e-17 9.07274827216e-17 8.97438947721e-17 8.8768129587e-17 8.78075846617e-17 8.68712343071e-17 8.59685457648e-17 8.51073567927e-17 8.42917195687e-17 8.35211266834e-17 8.27914721311e-17 8.20968309098e-17 8.14310220613e-17 8.07885334365e-17 8.01648722485e-17 7.95565642699e-17 7.89609946541e-17 7.83762097206e-17 7.78007355516e-17 7.72334317704e-17 7.66733808306e-17 7.61198068203e-17 7.55720194023e-17 7.50293754188e-17 7.44912563551e-17 7.39570569405e-17 7.3426181985e-17 7.2898048724e-17 7.23720951155e-17 7.18477869456e-17 7.13246281102e-17 7.08021693138e-17 7.02800155705e-17 6.97578328614e-17 6.92353525429e-17 6.87123744972e-17 6.81887680424e-17 6.76644719206e-17 6.71394926483e-17 6.6613901522e-17 6.60878305321e-17 6.55614678972e-17 6.50350518166e-17 6.45088646699e-17 6.39832261453e-17 6.34584862209e-17 6.29350181754e-17 6.24132113158e-17 6.18934643951e-17 6.13761789572e-17 6.08617530918e-17 6.03505759932e-17 5.98430230184e-17 5.93394510162e-17 5.88401948041e-17 5.83455641332e-17 5.78558412185e-17 5.73712788328e-17 5.68920991628e-17 5.64184930281e-17 5.59506194262e-17 5.54886058636e-17 5.50325485511e-17 5.45825131615e-17 5.41385358075e-17 5.37006240942e-17 5.32687585914e-17 5.28428940631e-17 5.24229611994e-17 5.20088686698e-17 5.16005050802e-17 5.11977414266e-17 5.08004336697e-17 5.0408425842e-17 5.00215533819e-17 4.96396469547e-17 4.92625361076e-17 4.8890053376e-17 4.85220379193e-17 4.81583395014e-17 4.77988213109e-17 4.74433626882e-17 4.70918608077e-17 4.67442320202e-17 4.64004124172e-17 4.60603577508e-17 4.57240429612e-17 4.53914613802e-17 4.50626234796e-17 4.47375551697e-17 4.44162957485e-17 4.40988950524e-17 4.37854098428e-17 4.3475899294e-17 4.31704195918e-17 4.28690172906e-17 4.25717218886e-17 4.22785381259e-17 4.19894390704e-17 4.17043605866e-17 4.14231998616e-17 4.11458189992e-17 4.08720541572e-17 4.06017293243e-17 4.03346710475e-17 4.00707216594e-17 3.98097494242e-17 3.95516553941e-17 3.92963766819e-17 3.90438822318e-17 3.879415467e-17 3.85471581951e-17 3.83027993927e-17 3.80608926099e-17 3.78211393236e-17 3.75831234781e-17 3.73463214225e-17 3.71101214411e-17 3.68738489168e-17 3.66367935974e-17 3.63982362056e-17 3.61574728264e-17 3.59138356467e-17 3.56667091886e-17 3.54155422023e-17 3.5159855043e-17 3.48992432725e-17 3.46333778759e-17 3.43620030308e-17 3.40849315608e-17 3.38020388424e-17 3.3513255769e-17 3.32185603495e-17 3.29179693039e-17 3.26115291983e-17 3.22993076015e-17 3.19813847099e-17 3.16578454348e-17 3.13287724452e-17 3.09942403179e-17 3.06543108796e-17 3.03090299051e-17 2.99584251849e-17 2.96025059952e-17 2.92412636403e-17 2.88746731685e-17 2.85026956257e-17 2.81252812505e-17 2.77423726079e-17 2.73539082218e-17 2.69598262181e-17 2.65600681722e-17 2.61545832535e-17 2.57433326952e-17 2.53262949396e-17 2.49034714147e-17 2.44748928e-17 2.40406263034e-17 2.36007832924e-17 2.31555276616e-17 2.27050843433e-17 2.22497481934e-17 2.17898926442e-17 2.13259785531e-17 2.08585619878e-17 2.03883015841e-17 1.99159645288e-17 1.94424309541e-17 1.89686959114e-17 1.84958687451e-17 1.80251689231e-17 1.75579178071e-17 1.70955261241e-17 1.66394762627e-17 1.61912997779e-17 1.57525502546e-17 1.53247719952e-17 1.4909465895e-17 1.45080537811e-17 1.41218432618e-17 1.37519949191e-17 1.33994938673e-17 1.30651274934e-17 1.27494706882e-17 1.24528792565e-17 1.21754915773e-17 1.19172378912e-17 1.16778563112e-17 1.14569136564e-17 1.12538298745e-17 1.10679038749e-17 1.08983397026e-17 1.07442714321e-17 1.06047860969e-17 1.04789439335e-17 1.03657956381e-17 1.02643967632e-17 1.01738191289e-17 1.00931599692e-17 1.00215486211e-17 9.95815159214e-18 9.90217624293e-18 9.85287320715e-18 9.80953811743e-18 9.77151261257e-18 9.73818488355e-18 9.70898984998e-18 9.68340886838e-18 9.66096913847e-18 9.64124268025e-18 9.62384494487e-18 9.60843298032e-18 9.59470319942e-18 9.58238883309e-18 9.57125702312e-18 9.56110571657e-18 9.55176043978e-18 9.54307102555e-18 9.53490842008e-18 9.52716155048e-18 9.51973452185e-18 9.51254394003e-18 9.505516653e-18 9.49858768466e-18 9.49169859069e-18 9.48479605729e-18 9.47783076393e-18 9.47075664485e-18 9.46353020732e-18 9.45611019375e-18 9.44845731288e-18 9.44053419296e-18 9.43230536707e-18 9.4237374034e-18 9.4147990323e-18 9.40546141382e-18 9.39569830471e-18 9.38548640891e-18 9.37480568223e-18 9.36363965893e-18 9.35197593984e-18 9.339806724e-18 9.32712944755e-18 9.31394766863e-18 9.30027229348e-18 9.28612312298e-18 9.27153097598e-18 9.25654088684e-18 9.24121620888e-18 9.22564483486e-18 9.20994810118e-18 9.19429366242e-18 9.17891433021e-18 9.16413499136e-18 9.15040905073e-18 9.13836019513e-18 9.12880235325e-18 9.12263550466e-18 9.12029930666e-18 9.12015823977e-18 9.11740342791e-18 9.11007256975e-18 9.09810230603e-18 9.07863662361e-18 9.0527366177e-18 9.02378592771e-18 8.99421692951e-18 8.96526470256e-18 8.93749818615e-18 8.91108767515e-18 8.88590814675e-18 8.86164073836e-18 8.83789680642e-18 8.81432469128e-18 8.79066910392e-18 8.76678304755e-18 8.74260896746e-18 8.71814817471e-18 8.69343075518e-18 8.66849209499e-18 8.64335702112e-18 8.6180308583e-18

Training - Random Suffule


In [ ]:
all_data = zip(xy_data,img_data)
shuffle(all_data)
temp_xy = []
temp_data = []
for row in all_data:
    temp_xy.append(row[0].tolist()[0])
    temp_data.append(row[1])

In [ ]:
s_data = np.matrix(temp_data)
s_xy = np.matrix(temp_xy)

Testing


In [19]:
showimg(fa2(xy_data.T)[0].T)



結論:

  • data 作 random suffule 的效果奇差,原因可以解釋為其實圖片的資料上下位置有相關系,如果 random 打散再作 mini batch ,反而喪失掉上下 pixle 之間相關的資料
  • 在 hidden layer 設 128 個 neuron解釋力較強,至於原因需要再探咎
  • 128 nerou
  • Training 過程
  • 256 nerou
  • Training 過程

In [ ]: