当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.decode_base64方法代码示例

本文整理汇总了Python中tensorflow.decode_base64方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.decode_base64方法的具体用法?Python tensorflow.decode_base64怎么用?Python tensorflow.decode_base64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.decode_base64方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_base64_tensor

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_base64 [as 别名]
def load_base64_tensor(_input):
    import tensorflow as tf

    def decode_and_process(base64):
        _bytes = tf.decode_base64(base64)
        _image = __tf_jpeg_process(_bytes)

        return _image

    # we have to do some preprocessing with map_fn, since functions like
    # decode_*, resize_images and crop_to_bounding_box do not support
    # processing of batches
    image = tf.map_fn(decode_and_process, _input,
                      back_prop=False, dtype=tf.float32)

    return image 
开发者ID:legolas123,项目名称:cv-tricks.com,代码行数:18,代码来源:image_utils.py

示例2: add_png_decoding

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_base64 [as 别名]
def add_png_decoding(input_width, input_height, input_depth):
  """Adds operations that perform PNG decoding and resizing to the graph..

  Args:
    input_width: The image width.
    input_height: The image height.
    input_depth: The image channels.

  Returns:
    Tensors for the node to feed PNG data into, and the output of the
      preprocessing steps.
  """
  base64_str = tf.placeholder(tf.string, name='input_string')
  input_str = tf.decode_base64(base64_str)
  decoded_image = tf.image.decode_png(input_str, channels=input_depth)
  # Convert from full range of uint8 to range [0,1] of float32.
  decoded_image_as_float = tf.image.convert_image_dtype(decoded_image,
                                                        tf.float32)
  decoded_image_4d = tf.expand_dims(decoded_image_as_float, 0)
  resize_shape = tf.stack([input_height, input_width])
  resize_shape_as_int = tf.cast(resize_shape, dtype=tf.int32)
  resized_image = tf.image.resize_bilinear(decoded_image_4d,
                                           resize_shape_as_int)
  tf.identity(resized_image, name="DecodePNGOutput")
  return input_str, resized_image 
开发者ID:mogoweb,项目名称:aiexamples,代码行数:27,代码来源:rebuild_model.py

示例3: _create_model

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_base64 [as 别名]
def _create_model(self, dir_name):
    """Create a simple model that takes 'key', 'num1', 'text1', 'img_url1' input."""

    def _decode_jpg(image):
      img_buf = BytesIO()
      Image.new('RGB', (16, 16)).save(img_buf, 'jpeg')
      default_image_string = base64.urlsafe_b64encode(img_buf.getvalue())
      image = tf.where(tf.equal(image, ''), default_image_string, image)
      image = tf.decode_base64(image)
      image = tf.image.decode_jpeg(image, channels=3)
      image = tf.reshape(image, [-1])
      image = tf.reduce_max(image)
      return image

    model_dir = tempfile.mkdtemp()
    with tf.Session(graph=tf.Graph()) as sess:
      record_defaults = [
          tf.constant([0], dtype=tf.int64),
          tf.constant([0.0], dtype=tf.float32),
          tf.constant([''], dtype=tf.string),
          tf.constant([''], dtype=tf.string),
      ]
      placeholder = tf.placeholder(dtype=tf.string, shape=(None,), name='csv_input_placeholder')
      key_tensor, num_tensor, text_tensor, img_tensor = tf.decode_csv(placeholder, record_defaults)
      text_tensor = tf.string_to_number(text_tensor, tf.float32)
      img_tensor = tf.map_fn(_decode_jpg, img_tensor, back_prop=False, dtype=tf.uint8)
      img_tensor = tf.cast(img_tensor, tf.float32)
      stacked = tf.stack([num_tensor, text_tensor, img_tensor])
      min_tensor = tf.reduce_min(stacked, axis=0)
      max_tensor = tf.reduce_max(stacked, axis=0)

      predict_input_tensor = tf.saved_model.utils.build_tensor_info(placeholder)
      predict_signature_inputs = {"input": predict_input_tensor}
      predict_output_tensor1 = tf.saved_model.utils.build_tensor_info(min_tensor)
      predict_output_tensor2 = tf.saved_model.utils.build_tensor_info(max_tensor)
      predict_key_tensor = tf.saved_model.utils.build_tensor_info(key_tensor)
      predict_signature_outputs = {
        'key': predict_key_tensor,
        'var1': predict_output_tensor1,
        'var2': predict_output_tensor2
      }
      predict_signature_def = (
          tf.saved_model.signature_def_utils.build_signature_def(
              predict_signature_inputs, predict_signature_outputs,
              tf.saved_model.signature_constants.PREDICT_METHOD_NAME
          )
      )
      signature_def_map = {
          signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: predict_signature_def
      }
      model_dir = os.path.join(self._test_dir, dir_name)
      builder = tf.saved_model.builder.SavedModelBuilder(model_dir)
      builder.add_meta_graph_and_variables(
          sess, [tf.saved_model.tag_constants.SERVING],
          signature_def_map=signature_def_map)
      builder.save(False)

    return model_dir 
开发者ID:googledatalab,项目名称:pydatalab,代码行数:60,代码来源:local_predict_tests.py

示例4: main

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import decode_base64 [as 别名]
def main():
  mnist = input_data.read_data_sets("./input_data")

  x = tf.placeholder(tf.float32, [None, 784])
  logits = inference(x)
  y_ = tf.placeholder(tf.int64, [None])
  cross_entropy = tf.losses.sparse_softmax_cross_entropy(
      labels=y_, logits=logits)
  train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

  init_op = tf.global_variables_initializer()

  # Define op for model signature
  tf.get_variable_scope().reuse_variables()

  model_base64_placeholder = tf.placeholder(
      shape=[None], dtype=tf.string, name="model_input_b64_images")
  model_base64_string = tf.decode_base64(model_base64_placeholder)
  model_base64_input = tf.map_fn(lambda x: tf.image.resize_images(tf.image.decode_jpeg(x, channels=1), [28, 28]), model_base64_string, dtype=tf.float32)
  model_base64_reshape_input = tf.reshape(model_base64_input, [-1, 28 * 28])
  model_logits = inference(model_base64_reshape_input)
  model_predict_softmax = tf.nn.softmax(model_logits)
  model_predict = tf.argmax(model_predict_softmax, 1)

  with tf.Session() as sess:

    sess.run(init_op)

    for i in range(938):
      batch_xs, batch_ys = mnist.train.next_batch(64)
      sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

    # Export image model
    export_dir = "./model/1"
    print("Try to export the model in {}".format(export_dir))
    tf.saved_model.simple_save(
        sess,
        export_dir,
        inputs={"images": model_base64_placeholder},
        outputs={
            "predict": model_predict,
            "probability": model_predict_softmax
        }) 
开发者ID:tobegit3hub,项目名称:tensorflow_examples,代码行数:45,代码来源:export_mnist_model.py


注:本文中的tensorflow.decode_base64方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。