保存到 TFRecord 时,我使用:
def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
def _bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def _float_feature(value):
return tf.train.Feature(float_list=tf.train.FloatList(value=value))
Run Code Online (Sandbox Code Playgroud)
和
one_example = tf.train.Example(
features=tf.train.Features(
feature={
"image": _bytes_feature(img.tobytes()),
"label": _bytes_feature(label.tobytes()),
"file_name": _bytes_feature(this_city_file_name), #this line doesn't work
"nb_rows": _int64_feature(nb_rows),
"nb_cols": _int64_feature(nb_cols),
"index_i": _int64_feature(i),
"index_j": _int64_feature(j),
}
)
)
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,this_city_file_name具有一种字符串类型,这会导致错误:
TypeError: 'xxxxxxx' has type ,但应为以下之一:((,),)
简单地使用 bytes(this_city_file_name) 也会导致错误:
类型错误:没有编码的字符串参数
从 TFRecord 加载时,我使用
features = tf.parse_single_example(serialized_example,
features={
"image": tf.FixedLenFeature([], tf.string),
"label": tf.FixedLenFeature([], tf.string),
"file_name": tf.FixedLenFeature([], tf.string),
"nb_rows": tf.FixedLenFeature([], tf.int64),
"nb_cols": tf.FixedLenFeature([], tf.int64),
"index_i": tf.FixedLenFeature([], tf.int64),
"index_j": …Run Code Online (Sandbox Code Playgroud) 在TensorFlow的Dataset API中,我们可以用来dataset.prefetch(buffer_size=xxx)在GPU处理当前批次的数据时预加载其他批次的数据,因此,我可以充分利用GPU。
我将使用Keras,想知道是否keras有类似的API让我充分利用GPU,而不是串行执行:读取批处理0->处理批处理0->读取批处理1->处理批处理1->。 ..
我简要浏览了一下kerasAPI,但没有看到有关预取的描述。
我有一个rgb语义分段标签,如果其中有3个类,并且每个RGB值是以下之一:
[255, 255, 0], [0, 255, 255], [255, 255, 255]
Run Code Online (Sandbox Code Playgroud)
然后,我想根据dict将RGB文件中的所有值映射到新的2D标签图像中:
{(255, 255, 0): 0, (0, 255, 255): 1, (255, 255, 255): 2}
Run Code Online (Sandbox Code Playgroud)
之后,新的灰色标签文件中的所有值都是0、1或2之一。是否有解决此问题的有效方法?例如在NumPy中广播。