def __init__(self, data_shape): self.data_shape = data_shape self.discriminator = None self.generator = None self.adversarial = None self.define_gan() self.noisy_samples = NoiseMaker(generator=self.generator) self.performance_output_path = 'performance/temp/' if not os.path.exists(self.performance_output_path): os.makedirs(self.performance_output_path)
def __init__(self, data_shape): """ Initialize SiDN-GAN """ self.data_shape = data_shape self.discriminator = None self.generator = None self.adversarial = None self.define_gan() self.noise_maker = NoiseMaker(shape=self.data_shape, noise_type='s&p') self.performance_output_path = 'performance/siamese_dn_gan_' + str( datetime.now().date())
# Warm up x = 0 for i in range(BASE_ITERATIONS): x += 1 op = "dirichlet.rvs() (scipy frozen distribution, size 9)" import scipy.stats # noqa d = scipy.stats.dirichlet([.2] * 9) with time_operation(op, BASE_ITERATIONS) as op: for i in range(op.num_interations): d.rvs() from noise_maker import NoiseMaker # noqa NOISE_MAKER = NoiseMaker(1000) op = "NOISE_MAKER.make_noise(.2, 10)" with time_operation(op, BASE_ITERATIONS) as op: for i in range(op.num_interations): NOISE_MAKER.make_noise(.2, 10) op = "random.randint(0, 9999)" with time_operation(op, BASE_ITERATIONS) as op: for i in range(op.num_interations): random.randint(0, 9999) op = "[0.0 for x in agents]" agents = [0, 1] with time_operation(op, BASE_ITERATIONS) as op: for i in range(op.num_interations): s = [0.0 for x in agents]
generated = generator.predict(noisy) # save the generator model model_file = path + '/model_%04d.h5' % (epoch + 1) generator.save(model_file) fig_file = path + '/plot_%04d' % ((epoch + 1)) measure_and_plot(original_images=test_data, noisy_images=noisy, generated_images=generated, path=fig_file) print('>Saved model and figures to', path) if __name__ == '__main__': dataset = Dataset(dataset='caltech256') dataset.split_test_data(test_sample=2000) noise_maker = NoiseMaker(shape=dataset.data_shape, noise_type='s&p') model_folder = 'C:/PycharmProjects/NeuralNetworks-GAN/performance/caltech256-128x128-siamese_dn_gan_2019-12-21' for epoch in range(20): generator_path = model_folder + '/epoch-%04d' % ( epoch + 1) + '/model_%04d.h5' % (epoch + 1) generator = load_model(generator_path) performance(generator, noise_maker, epoch, dataset.test_data, model_folder)
def __post_init__(self): super().__post_init__() self.noise_maker = NoiseMaker(1000) if self.policy_overrides is None: self.policy_overrides = [None, None]