# Buggy code
def print_mutation(hyp, results, yaml_file="hyp_evolved.yaml", bucket=""):
    # Print mutation results to evolve.txt (for use with train.py --evolve)
    a = "%10s" * len(hyp) % tuple(hyp.keys())  # hyperparam keys
    b = "%10.3g" * len(hyp) % tuple(hyp.values())  # hyperparam values
    c = (
        "%10.4g" * len(results) % results
    )  # results (P, R, mAP@0.5, mAP@0.5:0.95, val_losses x 3)
    print("\n%s\n%s\nEvolved fitness: %s\n" % (a, b, c))

    if bucket:
        os.system("gsutil cp gs://%s/evolve.txt ." % bucket)  # download evolve.txt

    with open("evolve.txt", "a") as f:  # append result
        f.write(c + b + "\n")
    x = np.unique(np.loadtxt("evolve.txt", ndmin=2), axis=0)  # load unique rows
    x = x[np.argsort(-fitness(x))]  # sort
    np.savetxt("evolve.txt", x, "%10.3g")  # save sort by fitness

    if bucket:
        os.system("gsutil cp evolve.txt gs://%s" % bucket)  # upload evolve.txt

    # Save yaml
    for i, k in enumerate(hyp.keys()):
        hyp[k] = float(x[0, i + 7])
    with open(yaml_file, "w") as f:
        results = x[0, :7]
        c = (
            "%10.4g" * len(results) % results
        )  # results (P, R, mAP@0.5, mAP@0.5:0.95, val_losses x 3)
        f.write(
            "# Hyperparameter Evolution Results\n# Generations: %g\n# Metrics: "
            % len(x)
            + c
            + "\n\n"
        )
        yaml.dump(hyp, f, sort_keys=False)


# Traceback (TypeError)
Traceback (most recent call last):
File "yolov5/train.py", line 516, in <module>
print_mutation(hyp, results, opt.bucket)
File "/content/drive/.shortcut-targets-by-id/1hQ281-8ogL2dJzHbXZSWEYDIYei6RRbe/YOLOv5/yolov5/utils/utils.py", line 830, in print_mutation
b = '%10.3g' * len(hyp) % tuple(hyp.values())  # hyperparam values
TypeError: must be real number, not str

# Fixed code
def print_mutation(hyp, results, yaml_file="hyp_evolved.yaml", bucket=""):
    # Print mutation results to evolve.txt (for use with train.py --evolve)
    a = "%10s" * len(hyp) % tuple(hyp.keys())  # hyperparam keys
    b = "%10.3g" * len(hyp) % tuple(hyp.values())  # hyperparam values
    c = (
        "%10.4g" * len(results) % results
    )  # results (P, R, mAP@0.5, mAP@0.5:0.95, val_losses x 3)
    print("\n%s\n%s\nEvolved fitness: %s\n" % (a, b, c))

    if bucket:
        os.system("gsutil cp gs://%s/evolve.txt ." % bucket)  # download evolve.txt

    with open("evolve.txt", "a") as f:  # append result
        f.write(c + b + "\n")
    x = np.unique(np.loadtxt("evolve.txt", ndmin=2), axis=0)  # load unique rows
    x = x[np.argsort(-fitness(x))]  # sort
    np.savetxt("evolve.txt", x, "%10.3g")  # save sort by fitness

    if bucket:
        os.system("gsutil cp evolve.txt gs://%s" % bucket)  # upload evolve.txt

    # Save yaml
    for i, k in enumerate(hyp.keys()):
        hyp[k] = float(x[0, i + 7])
    with open(yaml_file, "w") as f:
        results = tuple(x[0, :7])
        c = (
            "%10.4g" * len(results) % results
        )  # results (P, R, mAP@0.5, mAP@0.5:0.95, val_losses x 3)
        f.write(
            "# Hyperparameter Evolution Results\n# Generations: %g\n# Metrics: "
            % len(x)
            + c
            + "\n\n"
        )
        yaml.dump(hyp, f, sort_keys=False)