2

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

从互联网上的一些例子中,我还发现其中一个模型被训练用于检测汽车和人。所以我在其中输入了一些汽车的图像,它起作用了。

我现在正试图从 H5 文件本身中获取该信息,以便我可以将一些预期的输入和一些非预期的输入传递给检测器,看看会发生什么。

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

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

检测到的汽车和卡车的图像

正如我们在图像中看到的,矩形具有 和 之类的标签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 文件中获取单词car和单词truck,以便找出它的训练内容?

从评论中编辑:

我确信术语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")
4

1 回答 1

0

我认为这些术语不在代码中是错误的。它们不在我的代码中,而是在导入的 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

于 2019-12-26T19:18:27.623 回答