def display(self, style): """Display mode. Args: style (str): Name of the style. """ self.stl = Style(style, mc_version='1.15.2') with open(self.stl.info['schem_pth'], 'rb') as schem_file: o_tlmp = Schematic.load(schem_file, self.stl.info['mc_version']) g_tlmp = self.stl.generate(shape=(64, 16, 64)) o_w, o_h, o_l = o_tlmp.shape g_w, g_h, g_l = g_tlmp.shape spacing = 16 combined = Schematic(shape=( o_w + g_w + spacing, max(o_h, g_h), max(o_l, g_l), ), version=self.stl.info['mc_version']) combined[:o_w, :o_h, :o_l] = o_tlmp combined[o_w + spacing:, :g_h, :g_l] = g_tlmp app = App() app.tlmp = combined app.start_gui()
def train(self, style): """Training mode. This subcommand has no additional parameters. Args: style (str): Name of the style. """ self.stl = Style(style, mc_version='1.15.2') self.stl.train(vae=True, batch_size=64, epochs=300)
def test_load_save(self): # Creating stlye stl1 = Style('test_style', mc_version='1.15.2', icon_pth=join(dirname(__file__), 'icon_test.jpeg')) # Saving style stl1.save() # Loading stl2 = Style('test_style') self.assertEqual(stl1.name, stl2.name) self.assertEqual(stl1.info['mc_version'], stl2.info['mc_version'])
def test_init(self): stl = Style('test_style', mc_version='1.15.2', icon_pth=join(dirname(__file__), 'icon_test.jpeg')) with self.assertRaises(IconFileMissing): stl = Style('test_style', mc_version='1.15.2', icon_pth='this_img_does_not_exists.jpeg') with self.assertRaises(InvalidStyleName): stl = Style('test style with a space', mc_version='1.15.2', icon_pth=join(dirname(__file__), 'icon_test.jpeg'))
def display(self, style): """Display mode. This subcommand displays a plot of the latent space. Args: style (str): Name of the style. """ self.stl = Style(style, mc_version='1.15.2') vae = self.stl.models.vae vae_data = Tile.vectorize_all(self.stl.info['mc_version']) encodings = vae.encoder.predict(vae_data)[0] tiles = [ Tile('minecraft:quartz_stairs[half=bottom]', version='1.15.2'), Tile('minecraft:birch_stairs[half=bottom]', version='1.15.2'), Tile('minecraft:brick_stairs[half=bottom]', version='1.15.2'), Tile('minecraft:bricks', version='1.15.2'), Tile('minecraft:nether_bricks', version='1.15.2'), Tile('minecraft:white_carpet', version='1.15.2'), Tile('minecraft:snow[layers=1]', version='1.15.2') ] vae_data = vectorize(tiles, pad_to=vae.input_dim) encodings_subset = vae.encoder.predict(vae_data)[0] import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.scatter(encodings[:, 0], encodings[:, 1], c=[[.9, .9, .9]], marker='x') ax.scatter(encodings_subset[:, 0], encodings_subset[:, 1], color='r', marker='x') for idx, t in enumerate(tiles): ax.annotate(t.name, (encodings_subset[idx, 0], encodings_subset[idx, 1])) ax.set_title('Minecraft tile-ok 2D látenstere') plt.show()
def train(self, style, schem, batch_size=16, epochs=100): """Training mode. This subcommand optimizes a single tensor for the loss. Args: style (str): Name of the style. schem (str): Path to a schematic file. batch_size (int): Batch size. epochs (int): Epochs. """ self.stl = Style(style, mc_version='1.15.2') self.stl.info['schem_pth'] = schem vae = self.stl.models.vae self.stl.models.generator = DummyGeneratorNetwork(256, vae.latent_dim, shape=(32, 16, 32)) self.stl.models.generator.build() self.stl.train(generator=True, schem_pth=schem, batch_size=batch_size, epochs=epochs)
class LossTest(CommandlineInterface): """Testing feature-loss. This is a simple test program for the feature loss implemented in creAI/ml/losses/feature_loss.py """ def __init__(self): super(LossTest, self).__init__() @command def train(self, style, schem, batch_size=16, epochs=100): """Training mode. This subcommand optimizes a single tensor for the loss. Args: style (str): Name of the style. schem (str): Path to a schematic file. batch_size (int): Batch size. epochs (int): Epochs. """ self.stl = Style(style, mc_version='1.15.2') self.stl.info['schem_pth'] = schem vae = self.stl.models.vae self.stl.models.generator = DummyGeneratorNetwork(256, vae.latent_dim, shape=(32, 16, 32)) self.stl.models.generator.build() self.stl.train(generator=True, schem_pth=schem, batch_size=batch_size, epochs=epochs) @command def display(self, style): """Display mode. Args: style (str): Name of the style. """ self.stl = Style(style, mc_version='1.15.2') with open(self.stl.info['schem_pth'], 'rb') as schem_file: o_tlmp = Schematic.load(schem_file, self.stl.info['mc_version']) g_tlmp = self.stl.generate(shape=(64, 16, 64)) o_w, o_h, o_l = o_tlmp.shape g_w, g_h, g_l = g_tlmp.shape spacing = 16 combined = Schematic(shape=( o_w + g_w + spacing, max(o_h, g_h), max(o_l, g_l), ), version=self.stl.info['mc_version']) combined[:o_w, :o_h, :o_l] = o_tlmp combined[o_w + spacing:, :g_h, :g_l] = g_tlmp app = App() app.tlmp = combined app.start_gui()
class VaeTest(CommandlineInterface): """Testing VAE. This is a simple test program for the VAE implemented in creAI/ml/models/vae.py """ def __init__(self): super(VaeTest, self).__init__() @command def train(self, style): """Training mode. This subcommand has no additional parameters. Args: style (str): Name of the style. """ self.stl = Style(style, mc_version='1.15.2') self.stl.train(vae=True, batch_size=64, epochs=300) @command def display(self, style): """Display mode. This subcommand displays a plot of the latent space. Args: style (str): Name of the style. """ self.stl = Style(style, mc_version='1.15.2') vae = self.stl.models.vae vae_data = Tile.vectorize_all(self.stl.info['mc_version']) encodings = vae.encoder.predict(vae_data)[0] tiles = [ Tile('minecraft:quartz_stairs[half=bottom]', version='1.15.2'), Tile('minecraft:birch_stairs[half=bottom]', version='1.15.2'), Tile('minecraft:brick_stairs[half=bottom]', version='1.15.2'), Tile('minecraft:bricks', version='1.15.2'), Tile('minecraft:nether_bricks', version='1.15.2'), Tile('minecraft:white_carpet', version='1.15.2'), Tile('minecraft:snow[layers=1]', version='1.15.2') ] vae_data = vectorize(tiles, pad_to=vae.input_dim) encodings_subset = vae.encoder.predict(vae_data)[0] import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.scatter(encodings[:, 0], encodings[:, 1], c=[[.9, .9, .9]], marker='x') ax.scatter(encodings_subset[:, 0], encodings_subset[:, 1], color='r', marker='x') for idx, t in enumerate(tiles): ax.annotate(t.name, (encodings_subset[idx, 0], encodings_subset[idx, 1])) ax.set_title('Minecraft tile-ok 2D látenstere') plt.show()