コード例 #1
0
# Normalize all images
print("Normalizing query images")
imgs_query = normalize_img(imgs_query)
print("Normalizing gallery images")
imgs_gallery = normalize_img(imgs_gallery)

# Convert images to numpy array of right dimensions
print("\nConverting validation images to numpy array of right dimensions")
X_query = np.array(imgs_query).reshape((-1, ) + input_shape_model)
X_gallery = np.array(imgs_gallery).reshape((-1, ) + input_shape_model)
print(">>> X_query.shape = " + str(X_query.shape))
print(">>> X_gallery.shape = " + str(X_gallery.shape))

if args.mode != "training model":
    print("\nLoading model...")
    model.load_models(loss=args.loss, optimizer="adam")

# Create embeddings using model
print("\nCreating embeddings...")
E_query = model.predict(X_query)
E_query_flatten = E_query.reshape((-1, np.prod(output_shape_model)))
E_gallery = model.predict(X_gallery)
E_gallery_flatten = E_gallery.reshape((-1, np.prod(output_shape_model)))


# Compute top-k
def topk_accuracy(gt_label, matched_label, k=1):
    matched_label = matched_label[:, :k]
    total = matched_label.shape[0]
    correct = 0
    for q_idx, q_lbl in enumerate(gt_label):
コード例 #2
0
if args.model == 'convAE':

    # Build models
    autoencoderFile = os.path.join(OutputDir, "ConvAE_autoecoder.h5")
    print("autoencoder file", autoencoderFile)
    encoderFile = os.path.join(OutputDir, "ConvAE_encoder.h5")
    model = AutoEncoder(shape_img, autoencoderFile, encoderFile)
    model.set_arch()

    input_shape_model = tuple([int(x) for x in model.encoder.input.shape[1:]])
    output_shape_model = tuple(
        [int(x) for x in model.encoder.output.shape[1:]])

    # Loading model
    model.load_models(loss='mse', optimizer="adam")

    # Convert images to numpy array of right dimensions
    print("\nConverting to numpy array of right dimensions")
    X_query = np.array(QueryImgs).reshape((-1, ) + input_shape_model)
    X_gallery = np.array(GalleryImgs).reshape((-1, ) + input_shape_model)
    print(">>> X_query.shape = " + str(X_query.shape))
    print(">>> X_gallery.shape = " + str(X_gallery.shape))

    # Create embeddings using model
    print("\nCreating embeddings")
    E_query = model.predict(X_query)
    E_query_flatten = E_query.reshape((-1, np.prod(output_shape_model)))
    E_gallery = model.predict(X_gallery)
    E_gallery_flatten = E_gallery.reshape((-1, np.prod(output_shape_model)))