Skip to content

Scripts

Graphs

Datadynamics contains several scripts to generate graphs and point labels from image files to use in the graph_collector environment.

Generate Graphs From Masks

Script to generate input graphs to the graph_collector_v0 environment.

This script generates a graph with a grid-like structure from an obstacle mask file. Obstacles are encoding by black as default. The input obstacle mask file should be a binary image or an image that can be converted to one. The file should be a mask that represents the obstacles in the grid-like environment that the agent cannot traverse through.

main(args)

Generate graph from obstacle mask file.

Example usage: python -m datadynamics.scripts.graph.generate_graph -i ./data/obstacle_mask.png -o ./data/graph.pkl -m ./data/metadata.json -rs 100 100 -dfw 1.0

Source code in scripts/graph/generate_graph.py
def main(args):
    """Generate graph from obstacle mask file.

    Example usage:
    python -m datadynamics.scripts.graph.generate_graph \
        -i ./data/obstacle_mask.png \
        -o ./data/graph.pkl \
        -m ./data/metadata.json \
        -rs 100 100 \
        -dfw 1.0
    """
    graph, metadata = graph_extractor.from_mask_file(
        args.input_file,
        resize=args.resize,
        default_weight=args.default_weight,
        default_self_loop_weight=args.default_self_loop_weight,
        inverted=args.inverted,
        flip=args.flip,
    )

    with open(args.output_file, "wb") as f:
        pickle.dump(graph, f)
        print(f"Saved graph to {args.output_file}.")
    with open(args.metadata, "w") as f:
        json.dump(metadata, f, indent=4)
        print(f"Saved metadata to {args.metadata}.")

Generate Point Labels From Masks

Script to generate point labels for the graph_collector_v0 environment.

This script generates point labels used to represent points in a grid-like environment structure from a point mask file. Points are encoding by black as default. The input point mask file should be a binary image or an image that can be converted to one.

main(args)

Generate point labels from point mask file.

Example usage: python -m datadynamics.scripts.graph.generate_points -i ./data/point_mask.png -o ./data/point_labels.pkl -rs 100 100

Source code in scripts/graph/generate_points.py
def main(args):
    """Generate point labels from point mask file.

    Example usage:
    python -m datadynamics.scripts.graph.generate_points \
        -i ./data/point_mask.png \
        -o ./data/point_labels.pkl \
        -rs 100 100
    """
    point_labels = point_extractor.from_mask_file(
        args.input_file,
        resize=args.resize,
        inverted=args.inverted,
        flip=args.flip,
    )

    with open(args.output_file, "wb") as f:
        pickle.dump(point_labels, f)
        print(f"Saved point_labels to {args.output_file}.")