Skip to content

Instantly share code, notes, and snippets.

@BassyKuo
Created October 30, 2017 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BassyKuo/0a0731f58d743c9f3a58028ea67066ec to your computer and use it in GitHub Desktop.
Save BassyKuo/0a0731f58d743c9f3a58028ea67066ec to your computer and use it in GitHub Desktop.
Testing: Tensorflow orthogonal initializer
import tensorflow.contrib.slim as slim
import tensorflow as tf
import numpy as np
d_w_initializer = tf.orthogonal_initializer(1.0)
def discriminator(inputs, phase_train=True, reuse=False, use_bias=False, name="deGAN_d"):
net = inputs
pack = (
# [128, tf.nn.relu, d_w_initializer],
[128, tf.nn.relu, d_w_initializer],
[1, None, d_w_initializer]
)
with tf.variable_scope(name, reuse=reuse):
for (out_dim, nonlinear, weight_init) in pack:
net = slim.fully_connected(net, out_dim, activation_fn=nonlinear, weights_initializer=weight_init, trainable=phase_train)
net_sigmoid = tf.nn.sigmoid(net)
return net_sigmoid, net
x_vector = tf.placeholder(shape=[None, 2], dtype=tf.float32)
d_output_ax, d_output_x = discriminator(x_vector, phase_train=True, reuse=False, name="dis")
para_d = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, "dis")
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
for p in para_d:
param = sess.run(p)
print (p.name, ':', param)
"""
==Result==
[python2]
(u'dis/fully_connected/weights:0', ':', array([[-0.8475045 , 0.53078818, 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. ],
[-0.53078818, -0.8475045 , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , 0. , 0. ]], dtype=float32))
(u'dis/fully_connected/biases:0', ':', array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32))
(u'dis/fully_connected_1/weights:0', ':', array([[-0.11052871],
[-0.20991518],
[-0.04832305],
[ 0.05908521],
[-0.19491179],
[ 0.03560982],
[-0.06329771],
[-0.11723851],
[-0.06908984],
[ 0.02822152],
[ 0.01789066],
[-0.03971276],
[-0.13846675],
[ 0.22688815],
[ 0.01041574],
[-0.06114729],
[-0.06186278],
[-0.07697857],
[-0.08010832],
[ 0.08775618],
[ 0.03773334],
[-0.08370598],
[ 0.0388825 ],
[ 0.0147715 ],
[-0.01137062],
[ 0.08574435],
[-0.01399963],
[ 0.12237344],
[-0.11737294],
[-0.20274405],
[-0.07549576],
[ 0.14117518],
[-0.12110434],
[ 0.12576644],
[-0.07334179],
[-0.0340372 ],
[-0.1096774 ],
[-0.02330235],
[ 0.00684146],
[-0.09877077],
[ 0.07052406],
[ 0.06606247],
[-0.17143235],
[-0.05093653],
[-0.08917552],
[ 0.11809545],
[-0.11826695],
[ 0.11955678],
[ 0.14112419],
[-0.00313284],
[-0.03864501],
[-0.06109111],
[ 0.09925129],
[-0.10081473],
[-0.1500264 ],
[-0.0588489 ],
[-0.02176446],
[ 0.09641132],
[-0.07334175],
[-0.04272518],
[-0.01325776],
[ 0.0565419 ],
[ 0.05742063],
[ 0.12540603],
[ 0.07894526],
[ 0.04107035],
[-0.10473362],
[ 0.11693699],
[-0.1350707 ],
[ 0.1268793 ],
[ 0.08235937],
[-0.01445433],
[ 0.04467125],
[ 0.07695189],
[-0.06781199],
[ 0.06100395],
[ 0.07270169],
[ 0.0052122 ],
[ 0.01285983],
[ 0.07284614],
[ 0.01786022],
[-0.13000348],
[-0.08221045],
[ 0.00186574],
[-0.13192423],
[ 0.04438879],
[-0.09217983],
[ 0.10239365],
[-0.04636708],
[ 0.10392477],
[ 0.03118794],
[-0.13932098],
[ 0.04443027],
[-0.0439232 ],
[ 0.02250796],
[ 0.00155845],
[-0.16444997],
[ 0.10285532],
[-0.01705083],
[ 0.00973205],
[ 0.03515576],
[-0.09815874],
[ 0.10170943],
[-0.11517006],
[-0.00386532],
[-0.10950146],
[-0.01090297],
[ 0.07105645],
[-0.03340667],
[-0.09504166],
[ 0.0578483 ],
[-0.06948716],
[-0.05401714],
[ 0.01842865],
[ 0.01032768],
[ 0.00969856],
[ 0.07566746],
[ 0.07981603],
[-0.01383928],
[ 0.1256002 ],
[-0.06236145],
[-0.04916284],
[ 0.06115985],
[ 0.00413897],
[ 0.14074643],
[-0.04244688],
[-0.14975373],
[ 0.07554767]], dtype=float32))
(u'dis/fully_connected_1/biases:0', ':', array([ 0.], dtype=float32))
In [5]: w.dot(w.T)
Out[5]:
array([[ 9.99999940e-01, 1.62955871e-09],
[ 1.62955871e-09, 1.00000000e+00]], dtype=float32)
In [6]: w.T.dot(w)
Out[6]:
array([[ 9.99999970e-01, -1.14278417e-17, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ -1.14278417e-17, 9.99999970e-01, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
...,
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00]])
>>>--------------------------------------------------------------------<<<
[python3]
dis/fully_connected/weights:0 : [[ 0.04101396 0.00282262 0.11858316 -0.08793369 0.07026691 0.12383944
0.01990861 -0.04015915 -0.03329351 -0.10886138 0.00476262 -0.00440855
-0.07847943 0.04795551 0.0226737 -0.09886164 -0.06545945 -0.09471204
0.01504139 -0.04516091 -0.08151907 0.18103138 -0.05464819 0.03554351
0.0142109 -0.18541145 -0.20345342 0.01856319 0.04669981 -0.01990074
-0.04181176 -0.08076312 -0.08940034 -0.12072555 0.01287893 -0.10896289
-0.04309585 -0.06366444 -0.04434394 0.01093642 0.00500942 -0.06016422
0.05160751 0.02013115 0.05453434 0.15663838 0.02817832 0.05172544
-0.08159286 0.03679269 0.09004476 0.04012616 -0.03456557 0.14602436
-0.07752082 0.06238875 -0.07307194 -0.14862756 -0.02459775 -0.0223964
0.12922563 0.02707836 -0.09104732 0.00281721 -0.04034542 -0.1158208
0.00813358 -0.06504992 -0.14653876 -0.01163553 0.13288194 -0.03196229
0.05255081 0.18372169 -0.00652188 -0.11486003 -0.01062342 -0.08648714
0.19571114 0.01911644 -0.00276748 0.19087847 -0.00250892 -0.01091663
0.09660593 -0.01815944 -0.08653246 -0.00983779 0.05129658 -0.03772916
0.0051222 0.12822948 0.12598453 0.01383105 -0.0386808 -0.13278186
0.20663661 -0.15154557 0.19332829 -0.03191073 -0.00082059 0.05476334
0.01753254 0.13970239 -0.02910717 0.01058873 -0.01658816 -0.14836495
0.02797249 0.03848312 0.01864971 0.12415688 0.13664277 0.08072875
-0.0513984 -0.02303756 -0.03750367 -0.15237962 0.11467476 -0.00931398
-0.01670302 0.20247945 0.04957422 -0.19839735 0.01396525 0.03916515
0.0810058 0.02203106]
[-0.14742975 -0.02728525 0.00992871 0.07481753 0.04490415 -0.12411423
-0.02885916 -0.08635169 -0.09540216 -0.05561684 -0.10728564 -0.05970076
0.1286393 -0.01883743 -0.03377459 0.025204 0.03822058 0.01912657
0.13062204 -0.08903821 -0.02234734 -0.1238445 0.0630333 0.02809635
-0.10697514 -0.00334686 0.14368479 -0.0310409 -0.02913119 -0.06249609
0.12306565 0.05711684 0.10545925 -0.05589075 -0.1529551 -0.04909518
-0.11743014 0.08358652 -0.10813683 -0.11889429 -0.23661967 -0.04994529
-0.09724635 0.071362 0.0396256 -0.02662948 0.08678962 0.07387092
0.16443332 -0.03997824 0.06624553 -0.05064899 0.04515237 -0.03380128
-0.11965292 -0.12725201 -0.01446775 -0.11957824 0.08607013 -0.06104553
-0.01946485 -0.10400435 0.05720186 0.1888651 -0.08418576 -0.09264959
0.03068584 -0.17017737 -0.0675417 -0.09831875 0.07368154 0.10643143
-0.07814553 -0.07961353 -0.09928014 0.06764383 -0.00620002 -0.01263881
0.02535412 -0.04484975 0.06739106 0.05877525 0.17205481 -0.02613609
0.07874921 0.03736738 -0.00258939 -0.0206883 0.10269757 -0.15157753
-0.03827246 0.05289856 -0.03536506 0.05399363 0.0387798 0.08783425
0.06774539 -0.0870423 0.23021187 0.05915233 0.01555545 -0.07506923
0.03123798 0.04178525 -0.02356146 0.01114136 -0.09370949 0.16863187
0.07167052 0.05629136 -0.00183444 0.12087322 0.03377723 0.01891069
0.05749806 -0.13281778 0.01843878 -0.05238624 -0.20670266 -0.16157706
0.0402207 -0.00920806 -0.05932731 0.01520855 0.03731564 0.0510799
-0.01993307 -0.17446288]]
dis/fully_connected/biases:0 : [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0.]
dis/fully_connected_1/weights:0 : [[ 0.07342529]
[ 0.01956038]
[-0.08779625]
[ 0.03722991]
[ 0.00777318]
[-0.02592787]
[ 0.13119645]
[ 0.01010209]
[ 0.06094441]
[ 0.05747317]
[ 0.06814103]
[-0.06696268]
[-0.18894026]
[ 0.02864641]
[ 0.08590043]
[-0.04649118]
[ 0.19342984]
[ 0.08805602]
[-0.00247734]
[ 0.01286793]
[ 0.01981915]
[-0.10300804]
[ 0.07893188]
[-0.05208931]
[ 0.07608114]
[ 0.14873786]
[-0.0194218 ]
[ 0.18571337]
[-0.00067339]
[ 0.14605829]
[-0.02930565]
[-0.0807768 ]
[-0.01007824]
[ 0.05716282]
[ 0.074874 ]
[-0.0261479 ]
[-0.18333688]
[ 0.2327358 ]
[-0.03834946]
[ 0.09250855]
[ 0.06635547]
[-0.0227586 ]
[-0.0402413 ]
[ 0.00815933]
[ 0.08925389]
[ 0.05177639]
[ 0.0568619 ]
[ 0.06622353]
[-0.09418834]
[ 0.11299206]
[ 0.22595555]
[ 0.04440299]
[-0.00558915]
[-0.12442191]
[ 0.02361583]
[ 0.14989954]
[ 0.08613469]
[-0.10904151]
[-0.01001203]
[-0.02304006]
[ 0.02050388]
[-0.00443301]
[-0.02163528]
[-0.17069544]
[-0.13730177]
[-0.14250818]
[-0.06989366]
[ 0.04542844]
[ 0.03258291]
[-0.01349705]
[-0.01027212]
[ 0.13844845]
[ 0.04746017]
[ 0.08828718]
[-0.03611644]
[-0.06846735]
[ 0.05297909]
[-0.1018014 ]
[-0.01424329]
[ 0.19367684]
[-0.01990421]
[ 0.05649848]
[-0.00954451]
[ 0.03046225]
[ 0.06319997]
[-0.07210429]
[ 0.06024394]
[-0.09988958]
[-0.01302731]
[-0.05751506]
[ 0.01709301]
[-0.00924513]
[ 0.08137567]
[-0.04674917]
[-0.09110501]
[-0.11971572]
[ 0.00741339]
[ 0.11701717]
[-0.11910746]
[ 0.06633325]
[ 0.05009257]
[-0.07960783]
[ 0.18401781]
[-0.18398972]
[-0.01144164]
[-0.10111214]
[ 0.07075374]
[ 0.04825507]
[-0.08800127]
[-0.07251966]
[-0.12750325]
[-0.06199754]
[-0.03718765]
[ 0.09468796]
[-0.04627893]
[-0.01986916]
[-0.06776371]
[ 0.01625537]
[ 0.06127259]
[ 0.00942123]
[-0.04763466]
[-0.10115042]
[ 0.10581742]
[ 0.13374151]
[-0.03544288]
[ 0.10451265]
[-0.01468707]
[ 0.1451278 ]]
dis/fully_connected_1/biases:0 : [ 0.]
In [5]: w.dot(w.T)
Out[5]:
array([[ 9.99999821e-01, 2.99189935e-08],
[ 2.99189935e-08, 1.00000012e+00]], dtype=float32)
In [6]: w.T.dot(w)
Out[6]:
array([[ 2.34176759e-02, 4.13842453e-03, 3.39977699e-03, ...,
-5.92437945e-03, 6.26109587e-03, 2.66245995e-02],
[ 4.13842453e-03, 7.52452121e-04, 6.38074052e-05, ...,
-1.28317985e-03, 7.72527128e-04, 4.82244883e-03],
[ 3.39977699e-03, 6.38074052e-05, 1.41605446e-02, ...,
5.15148509e-03, 9.40801390e-03, 8.80321313e-04],
...,
[ -5.92437945e-03, -1.28317985e-03, 5.15148509e-03, ...,
4.14306531e-03, 2.15442525e-03, -8.04869737e-03],
[ 6.26109587e-03, 7.72527128e-04, 9.40801390e-03, ...,
2.15442525e-03, 6.95926789e-03, 5.26222493e-03],
[ 2.66245995e-02, 4.82244883e-03, 8.80321313e-04, ...,
-8.04869737e-03, 5.26222493e-03, 3.09226662e-02]], dtype=float32)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment