How to use the tensorflowjs.converters.common.TFJS_LAYERS_MODEL function in tensorflowjs

To help you get started, we’ve selected a few tensorflowjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tensorflow / tfjs / tfjs-converter / python / tensorflowjs / converters / converter.py View on Github external
input_format: Input format as a string.
    output_format: Output format as a string.

  Returns:
    A `tuple` of two strings:
      (standardized_input_format, standardized_output_format).
  """
  input_format_is_keras = (
      input_format in [common.KERAS_MODEL, common.KERAS_SAVED_MODEL])
  input_format_is_tf = (
      input_format in [common.TF_SAVED_MODEL,
                       common.TF_FROZEN_MODEL, common.TF_HUB_MODEL])
  if output_format is None:
    # If no explicit output_format is provided, infer it from input format.
    if input_format_is_keras:
      output_format = common.TFJS_LAYERS_MODEL
    elif input_format_is_tf:
      output_format = common.TFJS_GRAPH_MODEL
    elif input_format == common.TFJS_LAYERS_MODEL:
      output_format = common.KERAS_MODEL

  return (input_format, output_format)
github tensorflow / tfjs-converter / python / tensorflowjs / wizard.py View on Github external
'when': lambda answers: value_in_list(answers, common.INPUT_FORMAT,
                                                (common.KERAS_SAVED_MODEL,
                                                 common.TFJS_LAYERS_MODEL))
      }
github tensorflow / tfjs / tfjs-converter / python / tensorflowjs / converters / wizard.py View on Github external
'when': lambda answers: value_in_list(answers, common.OUTPUT_FORMAT,
                                                (common.TFJS_LAYERS_MODEL))
      },
github tensorflow / tfjs-converter / python / tensorflowjs / wizard.py View on Github external
for fname in os.listdir(input_path):
        fname = fname.lower()
        if fname.endswith('model.json'):
          filename = os.path.join(input_path, fname)
          if get_tfjs_model_type(filename) == common.TFJS_LAYERS_MODEL_FORMAT:
            input_path = os.path.join(input_path, fname)
            detected_input_format = common.TFJS_LAYERS_MODEL
            break
  elif os.path.isfile(input_path):
    if h5py.is_hdf5(input_path):
      detected_input_format = common.KERAS_MODEL
    elif input_path.endswith('saved_model.pb'):
      detected_input_format = common.TF_SAVED_MODEL
    elif (input_path.endswith('model.json') and
          get_tfjs_model_type(input_path) == common.TFJS_LAYERS_MODEL_FORMAT):
      detected_input_format = common.TFJS_LAYERS_MODEL

  return detected_input_format, input_path
github tensorflow / tfjs-converter / python / tensorflowjs / wizard.py View on Github external
'when': lambda answers: value_in_list(answers, common.OUTPUT_FORMAT,
                                                (common.TFJS_LAYERS_MODEL))
      },
github tensorflow / tfjs-converter / python / tensorflowjs / wizard.py View on Github external
if not path:
    return 'Please enter a valid path'
  if input_format == common.TF_HUB_MODEL:
    if not re.match(TFHUB_VALID_URL_REGEX, path):
      return """This is not an valid URL for TFHub module: %s,
        We expect a URL that starts with http(s)://""" % path
  elif not os.path.exists(path):
    return 'Nonexistent path for the model: %s' % path
  if input_format in (common.KERAS_SAVED_MODEL, common.TF_SAVED_MODEL):
    is_dir = os.path.isdir(path)
    if not is_dir and not path.endswith('saved_model.pb'):
      return 'The path provided is not a directory or pb file: %s' % path
    if (is_dir and
        not any(f.endswith('saved_model.pb') for f in os.listdir(path))):
      return 'Did not find a .pb file inside the directory: %s' % path
  if input_format == common.TFJS_LAYERS_MODEL:
    is_dir = os.path.isdir(path)
    if not is_dir and not path.endswith('model.json'):
      return 'The path provided is not a directory or json file: %s' % path
    if is_dir and not any(f.endswith('model.json') for f in os.listdir(path)):
      return 'Did not find the model.json file inside the directory: %s' % path
  if input_format == common.KERAS_MODEL:
    if not h5py.is_hdf5(path):
      return 'The path provided is not a keras model file: %s' % path
  return True
github tensorflow / tfjs / tfjs-converter / python / tensorflowjs / converters / wizard.py View on Github external
}, {
      'key': 's',
      'name': input_format_string('Tensorflow Saved Model',
                                  common.TF_SAVED_MODEL,
                                  detected_format),
      'value': common.TF_SAVED_MODEL,
  }, {
      'key': 'h',
      'name': input_format_string('TFHub Module',
                                  common.TF_HUB_MODEL,
                                  detected_format),
      'value': common.TF_HUB_MODEL,
  }, {
      'key': 'l',
      'name': input_format_string('TensoFlow.js Layers Model',
                                  common.TFJS_LAYERS_MODEL,
                                  detected_format),
      'value': common.TFJS_LAYERS_MODEL,
  }]
  formats.sort(key=lambda x: x['value'] != detected_format)
  return formats
github tensorflow / tfjs / tfjs-converter / python / tensorflowjs / converters / wizard.py View on Github external
return """This is not an valid URL for TFHub module: %s,
        We expect a URL that starts with http(s)://""" % path
  elif not os.path.exists(path):
    return 'Nonexistent path for the model: %s' % path
  if input_format in (common.KERAS_SAVED_MODEL, common.TF_SAVED_MODEL):
    is_dir = os.path.isdir(path)
    if not is_dir and not path.endswith('saved_model.pb'):
      return 'The path provided is not a directory or pb file: %s' % path
    if (is_dir and
        not any(f.endswith('saved_model.pb') for f in os.listdir(path))):
      return 'Did not find a .pb file inside the directory: %s' % path
    if input_format == common.KERAS_SAVED_MODEL:
      if detect_saved_model(input_path) != common.KERAS_SAVED_MODEL:
        return 'This is a saved model but not a keras saved model: %s' % path

  if input_format == common.TFJS_LAYERS_MODEL:
    is_dir = os.path.isdir(path)
    if not is_dir and not path.endswith('model.json'):
      return 'The path provided is not a directory or json file: %s' % path
    if is_dir and not any(f.endswith('model.json') for f in os.listdir(path)):
      return 'Did not find the model.json file inside the directory: %s' % path
  if input_format == common.KERAS_MODEL:
    if not h5py.is_hdf5(path):
      return 'The path provided is not a keras model file: %s' % path
  return True
github tensorflow / tfjs / tfjs-converter / python / tensorflowjs / converters / wizard.py View on Github external
'when': lambda answers: value_in_list(answers, common.INPUT_FORMAT,
                                                (common.TFJS_LAYERS_MODEL))
      },
github tensorflow / tfjs / tfjs-converter / python / tensorflowjs / converters / wizard.py View on Github external
input_path = input_path.strip()
  detected_input_format = None
  if re.match(TFHUB_VALID_URL_REGEX, input_path):
    detected_input_format = common.TF_HUB_MODEL
  elif os.path.isdir(input_path):
    if (any(fname.lower().endswith('saved_model.pb')
            for fname in os.listdir(input_path))):
      detected_input_format = detect_saved_model(input_path)
    else:
      for fname in os.listdir(input_path):
        fname = fname.lower()
        if fname.endswith('model.json'):
          filename = os.path.join(input_path, fname)
          if get_tfjs_model_type(filename) == common.TFJS_LAYERS_MODEL_FORMAT:
            input_path = os.path.join(input_path, fname)
            detected_input_format = common.TFJS_LAYERS_MODEL
            break
  elif os.path.isfile(input_path):
    if h5py.is_hdf5(input_path):
      detected_input_format = common.KERAS_MODEL
    elif input_path.endswith('saved_model.pb'):
      input_path = os.path.dirname(input_path)
      detected_input_format = detect_saved_model(input_path)
    elif (input_path.endswith('model.json') and
          get_tfjs_model_type(input_path) == common.TFJS_LAYERS_MODEL_FORMAT):
      detected_input_format = common.TFJS_LAYERS_MODEL

  return detected_input_format, input_path