I'm trying to attach a probability value to my bounding boxes. I am currently tracking two objects on the same image, and I transfer learn the vgg16 model using the Keras functional API.
vgg = VGG16(weights="imagenet", include_top=False, input_tensor=Input(shape=(224,224,3)))
vgg.trainable = False
def output_boundingbox_layer(name):
flatten_out = Flatten()(vgg.output)
bbox = Dense(512,activation="relu")(flatten_out)
bbox = Dense(256,activation="relu")(bbox)
bbox = Dense(128,activation="relu")(bbox)
bbox = Dense(64,activation="relu")(bbox)
bbox = Dense(32,activation="relu")(bbox)
#Dense layer with 4 nodes because there are 4 coordinates to consider,
#xmin, ymin, xmax, ymax --> the bounding box
bbox = Dense(4, activation="sigmoid", name = name)(bbox)
return bbox
model=Model(inputs = vgg.input, outputs=(bboxlayer, bboxlayer_2)
model.compile(loss=losses, optimizer=Adam(), metrics=["accuracy"], loss_weights=lossWeights)
history = model.fit(
train_images,
trainTargets,
validation_data=(
test_images,
testTargets
),
batch_size=32,
epochs=100,
verbose=1
)
I did not include the remaining dictionaries where I define the loss functions and loss weights as well as assigning the various test_train_split() arrays to keep this question relatively short. I'm predicting frame by frame on a test video and it does a pretty good job from a qualitative observation, however I would like to attach a probability value. I'm having troubles getting that information. Using decode_predictions() I get the following output:
#Prediction results
[array([[0.4525235 , 0.20031905, 0.6131844 , 0.46470878]], dtype=float32), array([[0.4420103 , 0.09556548, 0.533233 , 0.23276633]], dtype=float32)]
#Traceback from decode_prediction()
in decode_predictions
if len(preds.shape) != 2 or preds.shape[1] != 1000:
AttributeError: 'list' object has no attribute 'shape'
Even when I try indexing the list to just one array I still get a similar error. I was thinking about training a separate softmax network but that just seems excessive to load two models simultaneously.