def on_epoch_end(self, iternum, GAN, logs={}):
     out = io.BytesIO()
     val = None
     if self.title == 'genimg':
         plots.save_img_grid(GAN.genrtor,
                             GAN.noise_vect_len,
                             fname=out,
                             Xterm=False,
                             scale=GAN.cscale)
     elif self.title == 'pixhist':
         val = plots.pix_intensity_hist(GAN.val_imgs,
                                        GAN.genrtor,
                                        GAN.noise_vect_len,
                                        scaling=GAN.datascale,
                                        fname=out,
                                        Xterm=False)
     out.seek(0)
     image = _filebuf_to_tf_summary_img(out, self.title)
     summary = tf.Summary(
         value=[tf.Summary.Value(tag=self.title, image=image)])
     writer = tf.summary.FileWriter(GAN.expDir + 'logs/imgs')
     writer.add_summary(summary, iternum)
     writer.close()
     out.close()
     return val
Beispiel #2
0
run = './expts/' + config + '/run' + runId + '/'

modelpath = run + 'models/g_cosmo_best.h5'

if not os.path.isfile(modelpath):
    print("Error: File %s with pre-trained weights could not be found")
    sys.exit()

GAN = GANbuild.DCGAN(config, run)
GAN.genrtor.load_weights(modelpath)

# Plot generated images
plots.save_img_grid(GAN.genrtor,
                    GAN.noise_vect_len,
                    GAN.invtransform,
                    GAN.C_axis,
                    Xterm=True,
                    scale=GAN.cscale,
                    multichannel=GAN.multichannel)

# Plot pixel intensity histogram and calculate chi-square score
chi = plots.pix_intensity_hist(GAN.val_imgs,
                               GAN.genrtor,
                               GAN.noise_vect_len,
                               GAN.invtransform,
                               GAN.C_axis,
                               multichannel=GAN.multichannel,
                               Xterm=True)

# Plot power spectrum and calculate chi-square score
pschi = plots.pspect(GAN.val_imgs,
Beispiel #3
0
#z = Input(shape=(1,noise_vect_len))
#genimg = genrtor(z)
#discrim.trainable = False
#decision = discrim(genimg)
#stacked = Model(z, decision)
#stacked.compile(loss=lossfn, optimizer=keras.optimizers.Adam(lr=0.0002, beta_1=0.5))

noise_vects1 = np.random.normal(loc=0.0, size=(10, 1, noise_vect_len))

reals = real_imgs[:10, :, :, :]
fakes = genrtor.predict(noise_vects1)

#plots.save_realimg_grid(real_imgs, Xterm=True, scale='lin')
#plots.save_img_grid(genrtor, noise_vect_len, 0, Xterm=True, scale='pwr')
plots.save_img_grid(genrtor, noise_vect_len, 0, Xterm=True, scale='pwr')
plots.save_img_grid(genrtor, noise_vect_len, 0, Xterm=True, scale='pwr')
#wdw = [-1.1, 1.1, 1e-4, 3e4]
chi = plots.pix_intensity_hist(real_imgs,
                               genrtor,
                               noise_vect_len,
                               'lin',
                               Xterm=True)
plt.show()
print('Chi=%f' % chi)

#noise_vects1 = np.random.normal(loc=0.0, size=(127000, 1, noise_vect_len))
#fakes = genrtor.predict(noise_vects1)
#np.save('./data/gen/fullcrop.npy', fakes)
'''
print(discrim.predict(reals))