示例#1
0
        signature_inputs, signature_outputs,
        tf.saved_model.signature_constants.CLASSIFY_METHOD_NAME)
    # Save model.
    builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
    builder.add_meta_graph_and_variables(
        sess, [tf.saved_model.tag_constants.SERVING],
        signature_def_map={
            tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
            signature_def
        },
        main_op=tf.tables_initializer(),
        strip_default_attrs=True)
    builder.save()
    tf.logging.info('Model has been exported to %s' % export_dir)

    return signature_def


def main(unused_argv):
    if os.path.exists(FLAGS.export_dir):
        raise ValueError('export_dir already exists: exporting will fail')

    export_model(FLAGS.export_dir, FLAGS.export_for_serving, FLAGS.batch_size,
                 FLAGS.image_width, FLAGS.image_height)


if __name__ == '__main__':
    flags.mark_flag_as_required('dataset_name')
    flags.mark_flag_as_required('export_dir')
    app.run(main)
    def testStringRequired(self):
        res = FLAGS.string_foo_required
        self.assertEqual(res, "default_val")
        FLAGS.string_foo_required = "bar"
        self.assertEqual("bar", FLAGS.string_foo_required)

    def testNoneStringRequired(self):
        res = FLAGS.none_string_foo_required
        self.assertEqual(res, "default_val")
        FLAGS.none_string_foo_required = "bar"
        self.assertEqual("bar", FLAGS.none_string_foo_required)


def main(_):
    # unittest.main() tries to interpret the unknown flags, so use the
    # direct functions instead.
    runner = unittest.TextTestRunner()
    itersuite = unittest.TestLoader().loadTestsFromTestCase(FlagsTest)
    runner.run(itersuite)


if __name__ == "__main__":
    # Test command lines
    sys.argv.extend([
        "--bool_a", "--nobool_negation", "--bool_c=True", "--bool_d=False",
        "and_argument", "--none_string_foo_required=default_val"
    ])
    flags.mark_flag_as_required('string_foo_required')
    flags.mark_flags_as_required(['none_string_foo_required'])
    app.run()
示例#3
0
    res = FLAGS.string_foo_required
    self.assertEqual(res, "default_val")
    FLAGS.string_foo_required = "bar"
    self.assertEqual("bar", FLAGS.string_foo_required)

  def testNoneStringRequired(self):
    res = FLAGS.none_string_foo_required
    self.assertEqual(res, "default_val")
    FLAGS.none_string_foo_required = "bar"
    self.assertEqual("bar", FLAGS.none_string_foo_required)


def main(_):
  # unittest.main() tries to interpret the unknown flags, so use the
  # direct functions instead.
  runner = unittest.TextTestRunner()
  itersuite = unittest.TestLoader().loadTestsFromTestCase(FlagsTest)
  runner.run(itersuite)


if __name__ == "__main__":
  # Test command lines
  sys.argv.extend([
      "--bool_a", "--nobool_negation", "--bool_c=True", "--bool_d=False",
      "--none_string_foo_required=default_val",
      "and_argument"
  ])
  flags.mark_flag_as_required('string_foo_required')
  flags.mark_flags_as_required(['none_string_foo_required'])
  app.run()
示例#4
0
      tf.saved_model.CLASSIFY_METHOD_NAME)
  # Save model.
  builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(export_dir)
  builder.add_meta_graph_and_variables(
      sess, [tf.saved_model.SERVING],
      signature_def_map={
          tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
              signature_def
      },
      main_op=tf.compat.v1.tables_initializer(),
      strip_default_attrs=True)
  builder.save()
  tf.compat.v1.logging.info('Model has been exported to %s' % export_dir)

  return signature_def


def main(unused_argv):
  if os.path.exists(FLAGS.export_dir):
    raise ValueError('export_dir already exists: exporting will fail')

  export_model(FLAGS.export_dir, FLAGS.export_for_serving, FLAGS.batch_size,
               FLAGS.image_width, FLAGS.image_height)


if __name__ == '__main__':
  #flags.mark_flag_as_required('dataset_name')
  flags.mark_flag_as_required('export_dir')
  app.run(main)

from absl import app
from tensorflow.compiler.mlir.tfr.python.composite import Composite
from tensorflow.compiler.mlir.tfr.python.op_reg_gen import gen_register_op
from tensorflow.compiler.mlir.tfr.python.tfr_gen import tfr_gen_from_module
from tensorflow.python.platform import flags

FLAGS = flags.FLAGS

flags.DEFINE_string(
    'output', None,
    'Path to write the genereated register op file and MLIR file.')

flags.DEFINE_bool('gen_register_op', True,
                  'Generate register op cc file or tfr mlir file.')

flags.mark_flag_as_required('output')


@Composite('TestRandom', derived_attrs=['T: numbertype'], outputs=['o: T'])
def _composite_random_op():
    pass


def main(_):
    if FLAGS.gen_register_op:
        assert FLAGS.output.endswith('.cc')
        generated_code = gen_register_op(sys.modules[__name__], '_composite_')
    else:
        assert FLAGS.output.endswith('.mlir')
        generated_code = tfr_gen_from_module(sys.modules[__name__],
                                             '_composite_')
import os
import exporter

input_type = ["image_tensor","inputs"]
types = ["uint","float"]
flags.DEFINE_string('input_type','image_tensor','Type of input_node type,you can choice from '
                                                '[image_tensor,inputs]')
flags.DEFINE_string('data_type','uint','you can choice from [uint,float]')
flags.DEFINE_string('input_shape',None,"The inpnut_node's shape,if dimensions's values is -1,it's shape is unkown,"
                                       "but also you can specify for an input_node'shapes,default shape is [None,None,None,3]")
flags.DEFINE_string('pipline_config_path',None,"It's your model's config file's path")
flags.DEFINE_string('trained_checkpoint_prefix',None,"The path your */.ckpt")
flags.DEFINE_string('output_dict',None,"pb models output path")
flags.DEFINE_string('preprocess',None,"Wheather to add preprocess op into the final graph")
flags.DEFINE_string('postprocess',None,"Wheather to add a new output_nodes into the final graph")
flags.mark_flag_as_required('pipline_config_path')
flags.mark_flag_as_required('trained_checkpoint_prefix')
flags.mark_flag_as_required('output_dict')
FLAGS = flags.FLAGS

def main(_):
    if FLAGS.input_type not in input_type:
        raise ValueError("The input_type must be one from 'image_tensor' or 'inputs':{}".format(FLAGS.input_type))
    if FLAGS.data_type not in types:
        raise ValueError("The data_type must be one from 'uint' or float:{}".format(FLAGS.data_type))
    
    if not os.path.exists(FLAGS.pipline_config_path):
        raise FileNotFoundError("The file {} is not found".format(FLAGS.pipline_config_path))
    
    if not os.path.exists(FLAGS.output_dict):
        os.mkdir(FLAGS.output_dict)