import sugartensor as tf from data import SpeechCorpus, voca_size from model import * __author__ = '*****@*****.**' # set log level to debug tf.sg_verbosity(10) # # hyper parameters # batch_size = 16 # total batch size # # inputs # # corpus input tensor data = SpeechCorpus(batch_size=batch_size * tf.sg_gpus()) # mfcc feature of audio inputs = tf.split(data.mfcc, tf.sg_gpus(), axis=0) # target sentence label labels = tf.split(data.label, tf.sg_gpus(), axis=0) # sequence length except zero-padding
import sugartensor as tf from data import SpeechCorpus, voca_size, index2str from model import * import numpy as np from tqdm import tqdm from attacks import FastGradientMethod import pickle ################################################## ## Edited by Jade Huang ################################################## __author__ = '*****@*****.**' # set log level to debug tf.sg_verbosity(10) # command line argument for set_name tf.sg_arg_def(set=('valid', "'train', 'valid', or 'test'. The default is 'valid'")) tf.sg_arg_def(frac=( 1.0, "test fraction ratio to whole data set. The default is 1.0(=whole set)")) # # hyper parameters # # batch size batch_size = 16
import tensorflow as tf import sugartensor as sg from input_data import Surv from model import ResNet sg.sg_verbosity(10) batch_size = 32 data = Surv(batch_size=32) input_ = data.data label = data.label model = ResNet() inference_fn = model.inference # logit = model.inference(x) def my_loss(input_, labels, inference_fn, num_gpu=1): assert num_gpu >= 0 tower_loss = [] input_batch = tf.split(input_, num_gpu, axis=0) label_batch = tf.split(labels, num_gpu, axis=0) for i in range(num_gpu): with tf.device('/gpu:%d' % i): with tf.name_scope('gpu_%d' % i): reuse = False if i == 0 else True logit = inference_fn(input_batch[i], reuse=reuse)
import sugartensor as tf from model import * from tw_data import TwitData __author__ = '*****@*****.**' # set log level to debug tf.sg_verbosity(1) # # hyper parameters # batch_size = 8 # batch size # # inputs # data = TwitData(batch_size=batch_size) # source, target sentence x, y = data.source, data.target # shift target for training source y_in = tf.concat([tf.zeros((batch_size, 1), tf.sg_intx), y[:, :-1]], axis=1) # vocabulary size voca_size = data.voca_size # make embedding matrix for source and target emb_x = tf.sg_emb(name='emb_x', voca_size=voca_size, dim=latent_dim) emb_y = tf.sg_emb(name='emb_y', voca_size=voca_size, dim=latent_dim)
def main(argv): # set log level to debug tf.sg_verbosity(10) # # hyper parameters # size = 160, 147 batch_size = 1 # batch size # # inputs # pngName = argv png = tf.read_file(pngName) #png.thumbnail(size, Image.ANTIALIAS) #png = tf.resize(png1, (14,14)) myPNG = tf.image.decode_png(png) y = convert_image(pngName) x = tf.reshape(y, [1, 28, 28, 1]) print(x) # corrupted image x_small = tf.image.resize_bicubic(x, (14, 14)) x_bicubic = tf.image.resize_bicubic(x_small, (28, 28)).sg_squeeze() x_nearest = tf.image.resize_images( x_small, (28, 28), tf.image.ResizeMethod.NEAREST_NEIGHBOR).sg_squeeze() # # create generator # # I've used ESPCN scheme # http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Shi_Real-Time_Single_Image_CVPR_2016_paper.pdf # # generator network with tf.sg_context(name='generator', act='relu', bn=True): gen = (x.sg_conv(dim=32).sg_conv().sg_conv( dim=4, act='sigmoid', bn=False).sg_periodic_shuffle(factor=2).sg_squeeze()) # # run generator # fileName = "inPython.png" fig_name = "genImages/" + fileName #fig_name2 = 'asset/train/sample2.png' print("start") with tf.Session() as sess: with tf.sg_queue_context(sess): tf.sg_init(sess) # restore parameters saver = tf.train.Saver() #saver.restore(sess, tf.train.latest_checkpoint('asset/train/ckpt')) saver.restore( sess, tf.train.latest_checkpoint('python/asset/train/ckpt')) # run generator gt, low, bicubic, sr = sess.run( [x.sg_squeeze(), x_nearest, x_bicubic, gen]) # plot result #sr[0].thumbnail(size, Image.ANTIALIAS) plt.figure(figsize=(1, 1)) #plt.set_axis_off() hr = plt.imshow(sr[0], 'gray') plt.axis('tight') plt.axis('off') #ax.set_axis_off() #ax.thumbnail(size, Image.ANTIALIAS) #plt.savefig(fig_name,bbox_inches='tight',pad_inches=0,dpi=600) plt.savefig(fig_name, dpi=600) #tf.sg_info('Sample image saved to "%s"' % fig_name) plt.close() ##print (type (sr[0])) ##sourceImage = Image.fromarray(np.uint8(sr[0]) print("done")