Skip to content

Commit

Permalink
Merge pull request #891 from roboflow/fix/add_image_into_aggregated_p…
Browse files Browse the repository at this point in the history
…redictions

Add fix for the problem with inference-cli workflows predictions saving
  • Loading branch information
PawelPeczek-Roboflow authored Dec 19, 2024
2 parents 80af3da + 863407b commit 2f3133c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion inference/core/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.31.1"
__version__ = "0.31.2rc1"


if __name__ == "__main__":
Expand Down
7 changes: 5 additions & 2 deletions inference_cli/lib/workflows/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,15 @@ def aggregate_batch_processing_results(
file_descriptor.close()
all_results = [
os.path.join(output_directory, f, "results.json")
for f in all_processed_files
for f in sorted(all_processed_files)
if os.path.exists(os.path.join(output_directory, f, "results.json"))
]
decoded_content = []
for result_path in track(all_results, description="Grabbing processing results..."):
decoded_content.append(read_json(path=result_path))
content = read_json(path=result_path)
processed_file = result_path.split("/")[-2]
content["image"] = processed_file
decoded_content.append(content)
if aggregation_format is OutputFileType.JSONL:
aggregated_results_path = os.path.join(
output_directory, "aggregated_results.jsonl"
Expand Down
8 changes: 4 additions & 4 deletions tests/inference_cli/integration_tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def test_processing_images_directory_with_hosted_api(
result_csv = pd.read_csv(os.path.join(empty_directory, "aggregated_results.csv"))
assert len(result_csv) == 3
assert (
len(result_csv.columns) == 2
), "Two columns expected - predictions and deducted visualization"
len(result_csv.columns) == 3
), "3 columns expected - predictions and deducted visualization"


@pytest.mark.skipif(
Expand Down Expand Up @@ -238,8 +238,8 @@ def test_processing_images_directory_with_inference_package(
result_csv = pd.read_csv(os.path.join(empty_directory, "aggregated_results.csv"))
assert len(result_csv) == 3
assert (
len(result_csv.columns) == 2
), "Two columns expected - predictions and deducted visualization"
len(result_csv.columns) == 3
), "3 columns expected - predictions and deducted visualization"


@pytest.mark.skipif(
Expand Down
10 changes: 9 additions & 1 deletion tests/inference_cli/unit_tests/lib/workflows/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,25 @@ def test_aggregate_batch_processing_results_when_json_output_is_expected_and_res
if len(line.strip()) == 0:
continue
decoded_results.append(json.loads(line))
print(decoded_results)
assert (
decoded_results
== [
{
"some": "value",
"image": "other.jpg",
"other": 3.0,
"list_field": [1, 2, 3],
"object_field": {"nested": "value"},
},
{
"some": "value",
"image": "some.jpg",
"other": 3.0,
"list_field": [1, 2, 3],
"object_field": {"nested": "value"},
}
]
* 2
)


Expand Down

0 comments on commit 2f3133c

Please sign in to comment.