寻找H5 fi的意图

2024-04-25 04:11:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我下载了一些H5文件,据我目前的理解,这些文件包含了经过训练的图像识别模型。我可以使用Python、Keras、Tensorflow和ImageAI成功地将这些模型应用于图像。你知道吗

从互联网上的一些例子中,我还发现其中一个模型是经过训练的,用于检测汽车和人。所以我给它输入了一些汽车的图像,它就起作用了。你知道吗

我现在正试图从H5文件本身获取这些信息,这样我就可以将一些预期的输入和一些非预期的输入传递到检测器中,看看会发生什么。你知道吗

我搜索了Stack Overflow如何读取H5文件并从中获取信息[1][2][3][4],但我得到的所有输出只是一堆技术数据。你知道吗

让我们举个具体的例子。我有一个模型,显然可以识别汽车和卡车:

Image of cars and trucks detected

正如我们在图像中看到的,矩形有cartruck这样的标签,所以它可以识别对象的类型。我想从H5文件中得到确切的信息。你知道吗

我有

import h5py

def printH5Content(filename: str):
    with h5py.File(filename, 'r') as f:
        print("Keys: %s" % f.keys())
        a_group_key = list(f.keys())[0]
        print(list(f[a_group_key]))

printH5Content(model_path)

但它只给了我

Keys: <KeysViewHDF5 ['model_weights']>
['add_1', 'add_10', 'add_11', 'add_12', 'add_13', 'add_14', ... 'zero_padding2d_4', 'zero_padding2d_5']

此外,访客没有提供更多信息:

def printH5Content(filename: str):
    with h5py.File(filename, 'r') as f:
        f.visit(print)

如何从H5文件中获取cartruck这两个词,以便找出它的训练目的?

从评论中编辑:

我确信术语cartruck必须在H5文件中消除。我有3个输入:代码,H5模型和JPG图像。你知道吗

  1. JPG只是像素的排列。它对内容一无所知。你知道吗
  2. 我的代码只有6行,不包含任何术语
  3. 剩下的唯一选择就是H5文件

我的代码的最低版本是:

from imageai.Detection import ObjectDetection
detector = ObjectDetection()
detector.setModelTypeAsTinyYOLOv3()
detector.setModelPath("./models/yolo-tiny.h5")
detector.loadModel()
detection = detector.detectObjectsFromImage(input_image="./input/cars.jpg", output_image_path="./output/cars.jpg")

Tags: 文件代码模型图像add信息filenamecar
1条回答
网友
1楼 · 发布于 2024-04-25 04:11:25

我错误地认为这些术语不在代码中。它们不在我的代码中,而是在导入的ImageAI库中。这可以通过使用ImageAI来确认,而无需加载H5文件:

from imageai.Detection import ObjectDetection
detector = ObjectDetection()
detector.setModelTypeAsTinyYOLOv3()
for _, value in detector.numbers_to_names.items():
    print(value)

这给出了ImageAI可以检测到的80个项目的列表,包括cartruck。你知道吗

相关问题 更多 >