當前位置: 首頁>>代碼示例>>Python>>正文


Python synthetic_model.GenerateSingleCode方法代碼示例

本文整理匯總了Python中synthetic_model.GenerateSingleCode方法的典型用法代碼示例。如果您正苦於以下問題:Python synthetic_model.GenerateSingleCode方法的具體用法?Python synthetic_model.GenerateSingleCode怎麽用?Python synthetic_model.GenerateSingleCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在synthetic_model的用法示例。


在下文中一共展示了synthetic_model.GenerateSingleCode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GenerateSample

# 需要導入模塊: import synthetic_model [as 別名]
# 或者: from synthetic_model import GenerateSingleCode [as 別名]
def GenerateSample(filename, code_shape, layer_depth):
  # {0, +1} binary codes.
  # No conversion since the output file is expected to store
  # codes using {0, +1} codes (and not {-1, +1}).
  code = synthetic_model.GenerateSingleCode(code_shape)
  code = np.round(code)

  # Reformat the code so as to be compatible with what is generated
  # by the image encoder.
  # The image encoder generates a tensor of size:
  # iteration_count x batch_size x height x width x iteration_depth.
  # Here: batch_size = 1
  if code_shape[-1] % layer_depth != 0:
    raise ValueError('Number of layers is not an integer')
  height = code_shape[0]
  width = code_shape[1]
  code = code.reshape([1, height, width, -1, layer_depth])
  code = np.transpose(code, [3, 0, 1, 2, 4])

  int_codes = code.astype(np.int8)
  exported_codes = np.packbits(int_codes.reshape(-1))

  output = io.BytesIO()
  np.savez_compressed(output, shape=int_codes.shape, codes=exported_codes)
  with tf.gfile.FastGFile(filename, 'wb') as code_file:
    code_file.write(output.getvalue()) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:28,代碼來源:gen_synthetic_single.py

示例2: GenerateDataset

# 需要導入模塊: import synthetic_model [as 別名]
# 或者: from synthetic_model import GenerateSingleCode [as 別名]
def GenerateDataset(filename, count, code_shape):
  with tf.python_io.TFRecordWriter(filename) as tfrecord_writer:
    for _ in xrange(count):
      code = synthetic_model.GenerateSingleCode(code_shape)
      # Convert {0,1} codes to {-1,+1} codes.
      code = 2.0 * code - 1.0
      AddToTFRecord(code, tfrecord_writer) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:9,代碼來源:gen_synthetic_dataset.py


注:本文中的synthetic_model.GenerateSingleCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。