本文整理汇总了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())
示例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)