Example #1
0
model.load_weights(args.weights_path)
print(model.summary())

image_path = args.image_path
input_size = model.input_shape[1]
seguir = True
while seguir:
    try:
        # Load and process image
        im_array = IOProcessor().process_image(image_path, input_size)
        # Do the freaking prediction
        pred = model.predict(im_array)[0]
        # Filter by threshold
        pred = np.where(pred >= 0.5, 1, 0)  # the threshold can be in argument
        # Convert binary values to classes
        classes = []
        for i, p in enumerate(pred):
            if p == 1: classes.append(list(opts.CLASSES.keys())[i])
        # Add classification information on the image and display it
        im = Image.open(image_path).convert("RGBA")
        draw_text(im, classes, show=True)
    except FileNotFoundError:
        logger.alert(
            "File not found. The provided image path is not correct, please try a new one"
        )
    # Ask for input again!
    logger.alert("Provide a new .jpg image path, or say 'quit' to... quit")
    image_path = input()
    if image_path.strip().lower() == "quit":
        seguir = False
Example #2
0
# Save everything in h5!!
h5_name = "voc_classification_trainval_224.h5"
h5_path = os.path.join(args.outputs_path, h5_name)
with h5py.File(h5_path, "w") as file:
    file.create_dataset("features", data=features, dtype='float32')
    file.create_dataset("labels", data=labels, dtype='float32')
logger.success("Created h5 file {} successfully".format(h5_name))
logger.log("Absolute path of h5 file:", os.path.abspath(h5_path))


#### Try to do that on next experiment ####

# Update on datastore if it is not a windows platform
if not sys.platform.startswith("win"):
    logger.alert("This is not a windows platform, we try to update our features and labels on a datastore")

    from azureml.core import Workspace, Dataset
    from azureml.data.datapath import DataPath
    # Get workspace
    ws = Workspace(
        subscription_id=args.subscription_id,
        resource_group=args.resource_group,
        workspace_name=args.workspace_name
    )
    files = [
        h5_path
    ]
    datastore = ws.get_default_datastore()
    datastore.upload_files(
        files=files,