日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tf.lookup.StaticHashTable 用法

發(fā)布時間:2025/4/5 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tf.lookup.StaticHashTable 用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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_NUMBERclass_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])>)

總結

以上是生活随笔為你收集整理的tf.lookup.StaticHashTable 用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。