tf.lookup.StaticHashTable 用法
用法 TF lookup
2023-09-14 09:09:28 时间
tf.lookup.StaticHashTable 本质是tensorflow 内置字典,在yolov3 tf代码中多次应用
def load_tfrecord_dataset(file_pattern, class_file, size=416):
LINE_NUMBER = -1 # TODO: use tf.lookup.TextFileIndex.LINE_NUMBER
class_table = tf.lookup.StaticHashTable(tf.lookup.TextFileInitializer(
class_file, tf.string, 0, tf.int64, LINE_NUMBER, delimiter="\n"), -1)
files = tf.data.Dataset.list_files(file_pattern)
dataset = files.flat_map(tf.data.TFRecordDataset)
return dataset.map(lambda x: parse_tfrecord(x, class_table, size))
###### 在当前目录下新建文件 voc2012.names
aeroplane
bicycle
bird
boat
bottle
bus
car
cat
chair
cow
diningtable
dog
horse
motorbike
person
pottedplant
sheep
sofa
train
tvmonitor
import tensorflow as tf
class_table = tf.lookup.StaticHashTable(tf.lookup.TextFileInitializer(
class_file, tf.string, 0, tf.int64, LINE_NUMBER, delimiter="\n"), -1)
class_table.lookup(tf.constant(['cat','person']))
<tf.Tensor: shape=(2,), dtype=int64, numpy=array([ 7, 14])>
class_table.export()
(<tf.Tensor: shape=(20,), dtype=string, numpy=
array([b'cat', b'chair', b'dog', b'person', b'bird', b'motorbike',
b'bottle', b'car', b'bus', b'sheep', b'boat', b'train',
b'aeroplane', b'pottedplant', b'sofa', b'tvmonitor', b'cow',
b'diningtable', b'horse', b'bicycle'], dtype=object)>,
<tf.Tensor: shape=(20,), dtype=int64, numpy=
array([ 7, 8, 11, 14, 2, 13, 4, 6, 5, 16, 3, 18, 0, 15, 17, 19, 9,
10, 12, 1])>)
相关文章
- Vue_(Router路由)-vue-router路由的基本用法
- tf.nn.softmax_cross_entropy_with_logits的用法
- 有关日期的函数操作用法总结,to_date(),trunc(),add_months();
- 浅析C语言中strtol()函数与strtoul()函数的用法
- Python内置函数reversed()用法分析
- ThinkPHP中,display和assign用法详解
- Spinner用法案例
- Java多线程 -join用法
- JavaScript ECMAScript规范里对于分号semicolon用法最权威的定义
- TF之CNN:CNN实现mnist数据集预测 96%采用placeholder用法+2层C及其max_pool法+隐藏层dropout法+输出层softmax法+目标函数cross_entropy法+
- TF版本升级问题集合:成功解决由于不同的TensorFlow版本之间某些函数的用法引起的错误
- 94.第十九章 MySQL数据库 -- SQL语言分类和常见SQL用法(四)
- project 的用法
- 【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法
- python中logging模块的一些简单用法
- 【java基础】static和final关键字的作用及其用法详解
- rpm包管理器常见用法