class_docstr: Defines the GlyphAzznProblem class.
class_docstr_tok: ["Defines","the","GlyphAzznProblem","class","."]
docstr: Generate samples of target svg commands.
docstr_tok: ["Generate","samples","of","target","svg","commands","."]
code: def generate_samples(self, data_dir, tmp_dir, dataset_split):
      """Generate samples of target svg commands."""
      del tmp_dir  # unused argument
      if not hasattr(self, "splits"):
          tf.logging.info(
              "Loading binary_fp: train/test from {}".format(URL_SPLITS)
          )
          self.splits = {}
          for line in tf.gfile.Open(URL_SPLITS, "r").read().split("\n"):
              if line:
                  line = line.split(", ")
                  self.splits[line[0]] = line[1]
  
      if not tf.gfile.Exists(data_dir):
          tf.gfile.MakeDirs(data_dir)
  
      if not tf.gfile.Exists(os.path.join(data_dir, "mean.npz")):
          # FIRST, COPY THE MEAN/STDEV INTO DATA_DIR, in npz format
          for serialized_stats in tf.python_io.tf_record_iterator(
              RAW_STAT_FILE
          ):
              stats = tf.train.Example()
              stats.ParseFromString(serialized_stats)
              mean = np.array(
                  stats.features.feature["mean"].float_list.value
              )
              stdev = np.array(
                  stats.features.feature["stddev"].float_list.value
              )
              # also want to set mean[:4] to zeros and stdev[:4] to ones, because
              # these are the class labels
              mean = np.concatenate((np.zeros([4]), mean[4:]), axis=0)
              stdev = np.concatenate((np.ones([4]), stdev[4:]), axis=0)
              # finally, save
              np.save(
                  tf.gfile.Open(
                      os.path.join(data_dir, "mean.npz"), "w"
                  ),
                  mean,
              )
              np.save(
                  tf.gfile.Open(
                      os.path.join(data_dir, "stdev.npz"), "w"
                  ),
                  stdev,
              )
              logging.info("Generated mean and stdev npzs")
  
      for raw_data_file in tf.gfile.Glob(RAW_DATA_FILES):
          for serialized_example in tf.python_io.tf_record_iterator(
              raw_data_file
          ):
              example = tf.train.Example()
              example.ParseFromString(serialized_example)
  
              # determing whether this example belongs to a fontset in train or test
              this_bfp = str(
                  example.features.feature[
                      "binary_fp"
                  ].bytes_list.value[0]
              )
              if this_bfp not in self.splits:
                  # randomly sample 10% to be test, the rest is train
                  should_be_test = np.random.random() < 0.1
                  self.splits[this_bfp] = (
                      "test" if should_be_test else "train"
                  )
  
              if self.splits[this_bfp] != dataset_split:
                  continue
  
              yield {
                  "targets_sln": np.array(
                      example.features.feature[
                          "seq_len"
                      ].int64_list.value
                  )
                  .astype(np.int64)
                  .tolist(),
                  "targets_cls": np.array(
                      example.features.feature["class"].int64_list.value
                  )
                  .astype(np.int64)
                  .tolist(),
                  "targets_rel": np.array(
                      example.features.feature[
                          "sequence"
                      ].float_list.value
                  )
                  .astype(np.float32)
                  .tolist(),
                  "targets_rnd": np.array(
                      example.features.feature[
                          "rendered"
                      ].float_list.value
                  )
                  .astype(np.float32)
                  .tolist(),
              }
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from absl import logging
  from magenta.models.svg_vae import svg_utils
  import numpy
  from tensor2tensor.data_generators import generator_utils
  from tensor2tensor.data_generators import problem
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
label_desc: Use image node_id 10 for calling the GlyphAzznProblem obj's underlying member method code with example usage: obj.generate_samples(data_dir, tmp_dir, dataset_split) without return types