Esempio n. 1
0
    def get_media(self,media_id,file_path):
        """获取media"""
        try:
            url = self.create_get_media_url(media_id)
            data = HttpClient().get(url)
            utils.mkdir(os.path.dirname(file_path))
            f = open(file_path, 'wb')

            im = Image.open(BytesIO(data))
            im_file = BytesIO()

            im.save(im_file, format='png')
            im_data = im_file.getvalue()
            f.write(im_data)
            f.close()
            return 1
        except:
            return 0
Esempio n. 2
0
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"

flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_integer('batch_size', 64, '')
flags.DEFINE_integer('max_iter', 200000, '')
flags.DEFINE_integer('snapshot_interval', 1000, 'interval of snapshot')
flags.DEFINE_integer('evaluation_interval', 5000, 'interval of evalution')
flags.DEFINE_integer('display_interval', 100,
                     'interval of displaying log to console')
flags.DEFINE_float('adam_alpha', 0.0001, 'learning rate')
flags.DEFINE_float('adam_beta1', 0.5, 'beta1 in Adam')
flags.DEFINE_float('adam_beta2', 0.999, 'beta2 in Adam')
flags.DEFINE_integer('n_dis', 1, 'n discrminator train')

mkdir('tmp')

os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
INCEPTION_FILENAME = 'inception_score.pkl'
config = FLAGS.__flags

config = {k: FLAGS[k]._value for k in FLAGS}
generator = DCGANGenerator(**config)
discriminator = SNDCGAN_Discrminator(**config)
data_set = Cifar10(batch_size=FLAGS.batch_size)

global_step = tf.Variable(0, name="global_step", trainable=False)
increase_global_step = global_step.assign(global_step + 1)
is_training = tf.placeholder(tf.bool, shape=())
z = tf.placeholder(tf.float32,
                   shape=[None, generator.generate_noise().shape[1]])
Esempio n. 3
0
if FLAGS.isResNet is False:
    tmp_dir = 'tmp'
    snapshot_dir = 'snapshots'
    generator = DCGANGenerator(**config)
    discriminator = SNDCGAN_Discrminator(**config)
else:
    tmp_dir = 'resnet_tmp'
    snapshot_dir = 'resnet_snapshots'
    generator = ResNetGenerator(**config)
    discriminator = ResNetDiscrminator(**config)

INCEPTION_FILENAME = tmp_dir + '/' + INCEPTION_FILENAME
FID_FILENAME = tmp_dir + '/' + FID_FILENAME

mkdir(tmp_dir)

global_step = tf.Variable(0, name="global_step", trainable=False)
increase_global_step = global_step.assign(global_step + 1)
is_training = tf.placeholder(tf.bool, shape=())
z = tf.placeholder(tf.float32,
                   shape=[None, generator.generate_noise().shape[1]])
x_hat = generator(z, is_training=is_training)
x = tf.placeholder(tf.float32, shape=x_hat.shape)

d_fake = discriminator(x_hat, update_collection=None)
# Don't need to collect on the second call, put NO_OPS
d_real = discriminator(x, update_collection="NO_OPS")
# Softplus at the end as in the official code of author at chainer-gan-lib github repository
# d_loss = tf.reduce_mean(tf.nn.softplus(d_fake) + tf.nn.softplus(-d_real)) + 1e-3 * tf.reduce_mean(tf.get_collection('partialL2'))
d_loss = tf.reduce_mean(tf.nn.relu(1.0 - d_real)) + tf.reduce_mean(
Esempio n. 4
0
from hmc import HMCSampler

flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_integer('batch_size', 64, '')
flags.DEFINE_integer('max_iter', 200000, '')
flags.DEFINE_integer('snapshot_interval', 1000, 'interval of snapshot')
flags.DEFINE_integer('evaluation_interval', 5000, 'interval of evalution')
flags.DEFINE_integer('display_interval', 100,
                     'interval of displaying log to console')
flags.DEFINE_float('adam_alpha', 1e-4, 'learning rate')
flags.DEFINE_float('adam_beta1', 0.0, 'beta1 in Adam')
flags.DEFINE_float('adam_beta2', 0.999, 'beta2 in Adam')
flags.DEFINE_integer('n_dis', 1, 'n discrminator train')

mkdir('results')
mkdir('results/tmp')

os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
INCEPTION_FILENAME = 'inception_score.pkl'
config = FLAGS.__flags

config = {k: FLAGS[k]._value for k in FLAGS}
generator = Generator(**config)
discriminator = Discrminator(**config)
data_set = Cifar10(batch_size=FLAGS.batch_size)

global_step = tf.Variable(0, name="global_step", trainable=False)
increase_global_step = global_step.assign(global_step + 1)
is_training = tf.placeholder(tf.bool, shape=())
z = tf.placeholder(tf.float32,