mean = app.session.run(app.ts.final_mean)
    print(mean)
    msd = app.session.run(app.ts.final_msd)
    print(msd)
    std = np.sqrt(msd - mean**2)
    print(std)

    vec = np.random.normal(mean, std, [sample, len(std)])
    images = app.session.run(app.ts.y, {app.ts.vec: vec})  # [-1, 28, 28]
    # 将所有图片做成一张图片,每行20张小图
    images = np.reshape(images, [-1, col, 28, 28])  # [-1, 20, 28, 28]
    images = np.transpose(images, [0, 2, 1, 3])  # [-1, 28, 20, 28]
    images = np.reshape(images, [-1, col * 28])  # [-1, 28, 20 * 28]
    # images = np.transpose(images, [2, 0, 1]) # [20 * 28, -1, 28]
    # images = np.reshape(images, [col * 28, -1]) # [20 * 28, -1]
    # images = np.transpose(images, [1, 0]) # [-1, 20 * 28]
    cv2.imwrite(path, images * 255)


if __name__ == '__main__':
    tf.disable_eager_execution()
    tf.reset_default_graph()

    config = MyConfig()
    ds = read_data_sets(config.simple_path)
    app = myf.App(config)
    with app:
        app.train(ds_train=MyDS(ds.train, config),
                  ds_validation=MyDS(ds.validation, config))
        # predict(app, config.batch_size, config.image_path, config.col)
Beispiel #2
0
class MyDS:
    def __init__(self, ds, config):
        self.ds = ds
        self.lr = config.lr
        self.num_examples = ds.num_examples

    def next_batch(self, batch_size):
        xs, ys = self.ds.next_batch(batch_size)
        return xs, self.lr


class App:
    def __init__(self):
        pass


if __name__ == '__main__':
    cfg = MyConfig()
    cfg.from_cmd()
    print('_'*20)
    print(cfg)

    dss = read_data_sets(cfg.sample_path)
    app = myf.App(cfg)
    with app:
        app.train(MyDS(dss.train, cfg), MyDS(dss.validation, cfg))
        mean = app.session.run(app.ts.final_mean)
        print(mean)
        msd = app.session.run(app.ts.final_msd)  # 二阶原点矩
        print(np.sqrt(msd - mean**2))