Ejemplo n.º 1
0
data = tg.Target(nBits=nBits)
ckt = ct.Circuit(nHidden=nHidden, nBits=nBits)

gt = tf.placeholder(dtype=tf.float32)
sig = tf.placeholder(dtype=tf.float32)
hpred, acl = ckt.encode(sig)

enc_t = data.Eval(gt, hpred, acl)[0]

#########################################################################
# Start TF session
sess = tf.Session()
sess.run(tf.global_variables_initializer())

sigs, bits = data.uSamp(100000)
bits = np.sum(bits * np.reshape(2**np.arange(nBits), [1, nBits]), 1)

mfiles = glob('wts/*.model.npz')
for m in mfiles:
    if os.path.isfile(m + '.png'):
        continue
    ut.netload(ckt, m, sess)
    enc = sess.run(enc_t, feed_dict={sig: sigs})
    plt.Figure()
    plt.hold(True)
    plt.plot(sigs.flatten(), bits.flatten(), '-g', linewidth=2)
    plt.plot(sigs.flatten(), enc.flatten(), '-r', linewidth=2)
    plt.title(m)
    plt.savefig(m + '.png', dpi=120)
    plt.close()
Ejemplo n.º 2
0
#########################################################################
# Start TF session (respecting OMP_NUM_THREADS)
# Restore model if necessary

#gopt = tf.GPUOptions(per_process_gpu_memory_fraction=0.25)
gopt = tf.GPUOptions(allow_growth=True)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gopt))
try:
    sess.run(tf.global_variables_initializer())
except:
    sess.run(tf.initialize_all_variables())

if ockp.latest is not None:
    mprint("Loading model")
    ut.netload(ckt,wtdir+'/iter_%d.model.npz'%ockp.iter,sess)
    mprint("Loading state")
    ut.loadopt(opt,ckt.wts,[],wtdir+'/iter_%d.state.npz'%ockp.iter,sess)
    mprint("Done!")

niter = ockp.iter


#########################################################################
# Main training loop

mprint("Starting from Iteration %d" % niter)
while niter < maxiter:

    e1v_a, lv_a = 0., 0.
    for i in range(bgroup):
Ejemplo n.º 3
0
tStep = opt.minimize(loss + 1e-3 * tf.reduce_sum(tf.abs(ckt.wts['w1'])))

#########################################################################
# Start TF session (respecting OMP_NUM_THREADS)
# Restore model if necessary

gopt = tf.GPUOptions(per_process_gpu_memory_fraction=0.25)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gopt))
try:
    sess.run(tf.global_variables_initializer())
except:
    sess.run(tf.initialize_all_variables())

if ockp.latest is not None:
    mprint("Loading model")
    ut.netload(ckt, 'wts/iter_%d.model.npz' % ockp.iter, sess)
    mprint("Loading state")
    ut.loadopt(opt, ckt.wts, [], 'wts/iter_%d.state.npz' % ockp.iter, sess)
    mprint("Done!")

niter = ockp.iter

#########################################################################
# Main training loop

mprint("Starting from Iteration %d" % niter)
while niter < maxiter:

    e1v_a, e2v_a, lv_a = 0., 0., 0.
    for i in range(bgroup):
        sigs, bits = data.rSamp(bsz)