当前位置: 首页>>代码示例>>Python>>正文


Python sugartensor.sg_init方法代码示例

本文整理汇总了Python中sugartensor.sg_init方法的典型用法代码示例。如果您正苦于以下问题:Python sugartensor.sg_init方法的具体用法?Python sugartensor.sg_init怎么用?Python sugartensor.sg_init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sugartensor的用法示例。


在下文中一共展示了sugartensor.sg_init方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate

# 需要导入模块: import sugartensor [as 别名]
# 或者: from sugartensor import sg_init [as 别名]
def generate(sample_image): 
    start_time = time.time() 
 
    g = ModelGraph()
         
    with tf.Session() as sess:
        # We need to initialize variables in this case because the Variable `generator/x` will not restored.
        tf.sg_init(sess)
         
        vars = [v for v in tf.global_variables() if "generator" not in v.name]
        saver = tf.train.Saver(vars)
        saver.restore(sess, tf.train.latest_checkpoint('asset/train/ckpt'))
          
        i = 0
        while True:
            mse, _ = sess.run([g.mse, g.train_gen], {g.y: transform_image(sample_image)}) # (16, 28)
               
            if time.time() - start_time > 60: # Save every 60 seconds
                gen_image = sess.run(g.x)
                gen_image = np.squeeze(gen_image)
                misc.imsave('gen_images/%s/gen_%.2f.jpg' % (label, mse), gen_image)
                   
                start_time = time.time()
                i += 1
                if i == 60: break # Finish after 1 hour 
开发者ID:Kyubyong,项目名称:texture_generation,代码行数:27,代码来源:gen.py

示例2: run_generator

# 需要导入模块: import sugartensor [as 别名]
# 或者: from sugartensor import sg_init [as 别名]
def run_generator(num, x1, x2, fig_name='sample.png'):
    with tf.Session() as sess:

        tf.sg_init(sess)

        # restore parameters
        tf.sg_restore(sess, tf.train.latest_checkpoint('asset/train/infogan'), category='generator')

        # run generator
        imgs = sess.run(gen, {target_num: num,
                              target_cval_1: x1,
                              target_cval_2: x2})

        # plot result
        _, ax = plt.subplots(10, 10, sharex=True, sharey=True)
        for i in range(10):
            for j in range(10):
                ax[i][j].imshow(imgs[i * 10 + j], 'gray')
                ax[i][j].set_axis_off()
        plt.savefig('asset/train/infogan/' + fig_name, dpi=600)
        tf.sg_info('Sample image saved to "asset/train/infogan/%s"' % fig_name)
        plt.close()


#
# draw sample by categorical division
#

# fake image 
开发者ID:buriburisuri,项目名称:sugartensor,代码行数:31,代码来源:mnist_info_gan_eval.py

示例3: run_generator

# 需要导入模块: import sugartensor [as 别名]
# 或者: from sugartensor import sg_init [as 别名]
def run_generator(num, x1, x2, fig_name='sample.png'):
    with tf.Session() as sess:
        tf.sg_init(sess)
        # restore parameters
        saver = tf.train.Saver()
        saver.restore(sess, tf.train.latest_checkpoint('asset/train'))

        # run generator
        imgs = sess.run(gen, {target_num: num,
                              target_cval_1: x1,
                              target_cval_2: x2})

        # plot result
        _, ax = plt.subplots(10, 10, sharex=True, sharey=True)
        for i in range(10):
            for j in range(10):
                ax[i][j].imshow(imgs[i * 10 + j], 'gray')
                ax[i][j].set_axis_off()
        plt.savefig('asset/train/' + fig_name, dpi=600)
        tf.sg_info('Sample image saved to "asset/train/%s"' % fig_name)
        plt.close()


#
# draw sample by categorical division
#

# fake image 
开发者ID:buriburisuri,项目名称:ac-gan,代码行数:30,代码来源:generate.py

示例4: run_generator

# 需要导入模块: import sugartensor [as 别名]
# 或者: from sugartensor import sg_init [as 别名]
def run_generator(num, x1, x2, fig_name='sample.png'):
    with tf.Session() as sess:
        tf.sg_init(sess)
        # restore parameters
        saver = tf.train.Saver()
        saver.restore(sess, tf.train.latest_checkpoint('asset/train/ckpt'))

        # run generator
        imgs = sess.run(gen, {target_num: num,
                              target_cval_1: x1,
                              target_cval_2: x2})

        # plot result
        _, ax = plt.subplots(10, 10, sharex=True, sharey=True)
        for i in range(10):
            for j in range(10):
                ax[i][j].plot(imgs[i * 10 + j, :, 0], color='b', linewidth=0.25)
                # Turn off tick labels only
                # ax[i][j].set_axis_off()
                ax[i][j].set_xticks([])
                ax[i][j].set_yticks([])

        plt.savefig('asset/train/' + fig_name, dpi=600)
        tf.sg_info('Sample image saved to "asset/train/%s"' % fig_name)
        plt.close()


#
# draw sample by categorical division
#

# fake image 
开发者ID:jeanjerome,项目名称:semisupervised_timeseries_infogan,代码行数:34,代码来源:generate.py

示例5: run_generator

# 需要导入模块: import sugartensor [as 别名]
# 或者: from sugartensor import sg_init [as 别名]
def run_generator(num, x1, x2, fig_name='sample.png'):
    with tf.Session() as sess:
        tf.sg_init(sess)
        # restore parameters
        saver = tf.train.Saver()
        saver.restore(sess, tf.train.latest_checkpoint('asset/train/ckpt'))

        # run generator
        imgs = sess.run(gen, {target_num: num,
                              target_cval_1: x1,
                              target_cval_2: x2})

        # plot result
        _, ax = plt.subplots(10, 10, sharex=True, sharey=True)
        for i in range(10):
            for j in range(10):
                ax[i][j].plot(imgs[i * 10 + j, :, 0])
                ax[i][j].plot(imgs[i * 10 + j, :, 1])
                ax[i][j].set_axis_off()
        plt.savefig('asset/train/' + fig_name, dpi=600)
        tf.sg_info('Sample image saved to "asset/train/%s"' % fig_name)
        plt.close()


#
# draw sample by categorical division
#

# fake image 
开发者ID:buriburisuri,项目名称:timeseries_gan,代码行数:31,代码来源:generate.py

示例6: run_generator

# 需要导入模块: import sugartensor [as 别名]
# 或者: from sugartensor import sg_init [as 别名]
def run_generator(num, x1, x2, fig_name='sample.png'):
    with tf.Session() as sess:
        tf.sg_init(sess)
        # restore parameters
        saver = tf.train.Saver()
        saver.restore(sess, tf.train.latest_checkpoint('asset/train/ckpt'))

        # run generator
        imgs = sess.run(gen, {target_num: num,
                              target_cval_1: x1,
                              target_cval_2: x2})

        # plot result
        _, ax = plt.subplots(10, 10, sharex=True, sharey=True)
        for i in range(10):
            for j in range(10):
                ax[i][j].imshow(imgs[i * 10 + j], 'gray')
                ax[i][j].set_axis_off()
        plt.savefig('asset/train/' + fig_name, dpi=600)
        tf.sg_info('Sample image saved to "asset/train/%s"' % fig_name)
        plt.close()


#
# draw sample by categorical division
#

# fake image 
开发者ID:buriburisuri,项目名称:supervised_infogan,代码行数:30,代码来源:generate.py

示例7: main

# 需要导入模块: import sugartensor [as 别名]
# 或者: from sugartensor import sg_init [as 别名]
def main():  
    g = ModelGraph()
        
    with tf.Session() as sess:
        tf.sg_init(sess)

        # restore parameters
        saver = tf.train.Saver()
        saver.restore(sess, tf.train.latest_checkpoint('asset/train/ckpt'))
        
        hits = 0
        num_imgs = 0
        
        with tf.sg_queue_context(sess):
            # loop end-of-queue
            while True:
                try:
                    logits, y = sess.run([g.logits, g.y]) # (16, 28) 
                    preds = np.squeeze(np.argmax(logits, -1)) # (16,)
                     
                    hits += np.equal(preds, y).astype(np.int32).sum()
                    num_imgs += len(y)
                    print "%d/%d = %.02f" % (hits, num_imgs, float(hits) / num_imgs)
                except:
                    break
                
        print "\nFinal result is\n%d/%d = %.02f" % (hits, num_imgs, float(hits) / num_imgs)
                    
                    
                             
#                     fout.write(u"▌file_name: {}\n".format(f))
#                     fout.write(u"▌Expected: {}\n".format(label2cls[]))
#                     fout.write(u"▌file_name: {}\n".format(f))
#                     fout.write(u"▌Got: " + predicted + "\n\n") 
开发者ID:Kyubyong,项目名称:texture_generation,代码行数:36,代码来源:test.py

示例8: eval

# 需要导入模块: import sugartensor [as 别名]
# 或者: from sugartensor import sg_init [as 别名]
def eval(): 
    # Load graph
    g = Graph(mode="inference"); print("Graph Loaded")
        
    with tf.Session() as sess:
        # Initialize variables
        tf.sg_init(sess)

        # Restore parameters
        saver = tf.train.Saver()
        saver.restore(sess, tf.train.latest_checkpoint('asset/train'))
        print("Restored!")
        mname = open('asset/train/checkpoint', 'r').read().split('"')[1] # model name
        
        # Load data
        X, Sources, Targets = load_test_data()
        char2idx, idx2char = load_vocab()
        
        with codecs.open(mname, "w", "utf-8") as fout:
            list_of_refs, hypotheses = [], []
            for i in range(len(X) // Hp.batch_size):
                # Get mini-batches
                x = X[i*Hp.batch_size: (i+1)*Hp.batch_size] # mini-batch
                sources = Sources[i*Hp.batch_size: (i+1)*Hp.batch_size]
                targets = Targets[i*Hp.batch_size: (i+1)*Hp.batch_size]
                
                preds_prev = np.zeros((Hp.batch_size, Hp.maxlen), np.int32)
                preds = np.zeros((Hp.batch_size, Hp.maxlen), np.int32)        
                for j in range(Hp.maxlen):
                    # predict next character
                    outs = sess.run(g.preds, {g.x: x, g.y_src: preds_prev})
                    # update character sequence
                    if j < Hp.maxlen - 1:
                        preds_prev[:, j + 1] = outs[:, j]
                    preds[:, j] = outs[:, j]
                
                # Write to file
                for source, target, pred in zip(sources, targets, preds): # sentence-wise
                    got = "".join(idx2char[idx] for idx in pred).split(u"␃")[0]
                    fout.write("- source: " + source +"\n")
                    fout.write("- expected: " + target + "\n")
                    fout.write("- got: " + got + "\n\n")
                    fout.flush()
                    
                    # For bleu score
                    ref = target.split()
                    hypothesis = got.split()
                    if len(ref) > 2:
                        list_of_refs.append([ref])
                        hypotheses.append(hypothesis)
            
            # Get bleu score
            score = corpus_bleu(list_of_refs, hypotheses)
            fout.write("Bleu Score = " + str(100*score)) 
开发者ID:Kyubyong,项目名称:quasi-rnn,代码行数:56,代码来源:eval.py


注:本文中的sugartensor.sg_init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。