IndexError: index 917 is out of bounds for axis 0 with size 11, on npargmax in tensorflow
IndexError: index 917 is out of bounds for axis 0 with size 11, on npargmax in tensorflow
我正在使用示例here
对图像进行分类。我有 2147 张图像,属于 11 类。我是 运行 一批图像的分类器。到目前为止程序进展顺利,但我无法分配标签,因为我在代码中收到以下错误:labels_batch=image_labels[np.argmax(result_batch, axis=-1)]
Traceback (most recent call last): > > labels_batch=image_labels[np.argmax(result_batch, axis=-1)]
IndexError: index 917 is out of bounds for axis 0 with size 11
更多信息:
我的标签是 categories = ["Categorical_Boxplot", "Column_Charts", "Dendogram", "Heatmap", "Line_Chart", "Map","Node-Link_Diagram", "Ordination_Scatterplot", "Pie_Chart", "Scatterplot", "Stacked_Area_Chart"]
这是我尝试将此标签分配给分类器的方式
image_labels = np.array(categories)
result_batch = classifier_model.predict(image_batch)
labels_batch = image_labels[np.argmax(result_batch, axis=-1)]
labels_batch
result_batch.shape
(32, 1001)
我的数据的形状
Image batch shape: (32, 224, 224, 3)
Label batch shape: (32, 11)
我不知道哪里出了问题,我该如何解决?我已经尝试将 image_labels 附加到 labels_batch 而不是用 =
分配它。但是没有用。
分类器:
classifier_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/2" #@param {type:"string"}
IMAGE_SIZE = hub.get_expected_image_size(hub.Module(classifier_url))
classifier_layer = layers.Lambda(classifier, input_shape=IMAGE_SIZE + [3])
classifier_model = tf.keras.Sequential([classifier_layer])
classifier_model.summary()
您的模型定义不完整。教程中的模型有 1001 个 类 而你的模型只有 11 个,所以你应该像这样将一个新的经典小说头附加到你的模型。
classifier_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/2" #@param {type:"string"}
IMAGE_SIZE = hub.get_expected_image_size(hub.Module(classifier_url))
classifier_layer = layers.Lambda(classifier, input_shape=IMAGE_SIZE + [3])
classifier_model = tf.keras.Sequential([classifier_layer, layers.Dense(11, activation='softmax')])
classifier_model.summary()
我正在使用示例here
对图像进行分类。我有 2147 张图像,属于 11 类。我是 运行 一批图像的分类器。到目前为止程序进展顺利,但我无法分配标签,因为我在代码中收到以下错误:labels_batch=image_labels[np.argmax(result_batch, axis=-1)]
Traceback (most recent call last): > > labels_batch=image_labels[np.argmax(result_batch, axis=-1)] IndexError: index 917 is out of bounds for axis 0 with size 11
更多信息:
我的标签是 categories = ["Categorical_Boxplot", "Column_Charts", "Dendogram", "Heatmap", "Line_Chart", "Map","Node-Link_Diagram", "Ordination_Scatterplot", "Pie_Chart", "Scatterplot", "Stacked_Area_Chart"]
这是我尝试将此标签分配给分类器的方式
image_labels = np.array(categories)
result_batch = classifier_model.predict(image_batch)
labels_batch = image_labels[np.argmax(result_batch, axis=-1)]
labels_batch
result_batch.shape
(32, 1001)
我的数据的形状
Image batch shape: (32, 224, 224, 3) Label batch shape: (32, 11)
我不知道哪里出了问题,我该如何解决?我已经尝试将 image_labels 附加到 labels_batch 而不是用 =
分配它。但是没有用。
分类器:
classifier_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/2" #@param {type:"string"}
IMAGE_SIZE = hub.get_expected_image_size(hub.Module(classifier_url))
classifier_layer = layers.Lambda(classifier, input_shape=IMAGE_SIZE + [3])
classifier_model = tf.keras.Sequential([classifier_layer])
classifier_model.summary()
您的模型定义不完整。教程中的模型有 1001 个 类 而你的模型只有 11 个,所以你应该像这样将一个新的经典小说头附加到你的模型。
classifier_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/2" #@param {type:"string"}
IMAGE_SIZE = hub.get_expected_image_size(hub.Module(classifier_url))
classifier_layer = layers.Lambda(classifier, input_shape=IMAGE_SIZE + [3])
classifier_model = tf.keras.Sequential([classifier_layer, layers.Dense(11, activation='softmax')])
classifier_model.summary()