Skip to content

Commit

Permalink
Fixed the issue with just 1 image showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
naitikjain3071 committed Oct 13, 2024
1 parent b56a862 commit 7b971cb
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ a bug or feature that you would like to see implemented, please don't hesitate t
See the [contributing guidelines](/CONTRIBUTING.md) for more information.

## Funding
This project is partly funded by the [National AI Institute for Food Systems (AIFS)](https://aifs.ucdavis.edu
This project is partly funded by the [National AI Institute for Food Systems (AIFS)](https://aifs.ucda
36 changes: 18 additions & 18 deletions agml/_assets/public_datasources.json
Original file line number Diff line number Diff line change
Expand Up @@ -1327,14 +1327,14 @@
"docs_url": "https://www.kaggle.com/datasets/smaranjitghose/corn-or-maize-leaf-disease-dataset/data",
"stats": {
"mean": [
0.4375976324081421,
0.49800223112106323,
0.37561240792274475
0.4375974237918854,
0.49800145626068115,
0.37561285495758057
],
"std": [
0.17942127585411072,
0.16718918085098267,
0.17422522604465485
0.17942166328430176,
0.1671891063451767,
0.17422519624233246
]
}
},
Expand Down Expand Up @@ -1368,14 +1368,14 @@
"docs_url": "https://www.kaggle.com/datasets/kaustubhb999/tomatoleaf?resource=download",
"stats": {
"mean": [
0.45274582505226135,
0.46330446004867554,
0.41868868470191956
0.4527459740638733,
0.4633057117462158,
0.41868820786476135
],
"std": [
0.16920873522758484,
0.14771881699562073,
0.18538568913936615
0.16920849680900574,
0.14771871268749237,
0.1853858381509781
]
}
},
Expand Down Expand Up @@ -1406,14 +1406,14 @@
"docs_url": "",
"stats": {
"mean": [
0.44989293813705444,
0.44891005754470825,
0.2950020432472229
0.44989314675331116,
0.44891050457954407,
0.2950022220611572
],
"std": [
0.2310590147972107,
0.2280452400445938,
0.23016883432865143
0.23105928301811218,
0.22804518043994904,
0.23016895353794098
]
}
}
Expand Down
76 changes: 57 additions & 19 deletions agml/viz/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,81 @@
from agml.viz.tools import format_image, _inference_best_shape, convert_figure_to_image
from agml.viz.display import display_image

def show_sample(loader, image_only=False, num_images=1, **kwargs):
"""A simplified convenience method that visualizes multiple samples from a loader.
def show_sample(loader, image_only = False, **kwargs):
"""A simplified convenience method that visualizes a sample from a loader.
This method works for all kind of annotations; it picks the appropriate
visualization method and then calls it with a sample from the loader.
If you want to customize the way the output looks, then you need to use
the actual methods directly.
This method works for all types of annotations and visualizes multiple
images based on the specified `num_images` parameter.
Parameters
----------
loader : AgMLDataLoader
An AgMLDataLoader of any annotation type.
image_only : bool
Whether to only display the image.
Whether to only display the images.
num_images : int
The number of images to display (default is 1).
Returns
-------
The matplotlib figure.
The matplotlib figure showing the requested number of images.
"""
if kwargs.get('sample', None) is not None:
sample = kwargs['sample']
else:
sample = loader[0]
# Fetch the requested number of samples from the loader.
samples = [loader[i] for i in range(num_images)]

# Visualize the images based on the task.
if image_only:
return show_images(sample[0])
return show_images([sample[0] for sample in samples])

if loader.task == 'object_detection':
return show_image_and_boxes(
sample, info = loader.info, no_show = kwargs.get('no_show', False))
return [show_image_and_boxes(
sample, info=loader.info, no_show=kwargs.get('no_show', False))
for sample in samples]
elif loader.task == 'semantic_segmentation':
return show_image_and_overlaid_mask(
sample, no_show = kwargs.get('no_show', False))
return [show_image_and_overlaid_mask(
sample, no_show=kwargs.get('no_show', False))
for sample in samples]
elif loader.task == 'image_classification':
return show_images_and_labels(
sample, info = loader.info, no_show = kwargs.get('no_show', False))
samples, info=loader.info, no_show=kwargs.get('no_show', False))


# def show_sample(loader, image_only = False, **kwargs):
# """A simplified convenience method that visualizes a sample from a loader.

# This method works for all kind of annotations; it picks the appropriate
# visualization method and then calls it with a sample from the loader.
# If you want to customize the way the output looks, then you need to use
# the actual methods directly.

# Parameters
# ----------
# loader : AgMLDataLoader
# An AgMLDataLoader of any annotation type.
# image_only : bool
# Whether to only display the image.

# Returns
# -------
# The matplotlib figure.
# """
# if kwargs.get('sample', None) is not None:
# sample = kwargs['sample']
# else:
# sample = loader[0]

# if image_only:
# return show_images(sample[0])

# if loader.task == 'object_detection':
# return show_image_and_boxes(
# sample, info = loader.info, no_show = kwargs.get('no_show', False))
# elif loader.task == 'semantic_segmentation':
# return show_image_and_overlaid_mask(
# sample, no_show = kwargs.get('no_show', False))
# elif loader.task == 'image_classification':
# return show_images_and_labels(
# sample, info = loader.info, no_show = kwargs.get('no_show', False))


def show_images(images,
Expand Down
9 changes: 7 additions & 2 deletions docs/datasets/corn_maize_leaf_disease.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
| **Annotation Format** | directory_names |
| **Number of Images** | 4188 |
| **Documentation** | https://www.kaggle.com/datasets/smaranjitghose/corn-or-maize-leaf-disease-dataset/data |
| **Stats/Mean** | [0.4375976324081421, 0.49800223112106323, 0.37561240792274475] |
| **Stats/Standard Deviation** | [0.17942127585411072, 0.16718918085098267, 0.17422522604465485] |
| **Stats/Mean** | [0.438, 0.498, 0.376] |
| **Stats/Standard Deviation** | [0.179, 0.167, 0.174] |


## Examples

![Example Images for corn_maize_leaf_disease](https://github.com/Project-AgML/AgML/blob/dev/docs/sample_images/corn_maize_leaf_disease_examples.png)
2 changes: 2 additions & 0 deletions docs/datasets/vine_virus_photo_dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
| **Annotation Format** | directory_names |
| **Number of Images** | 3866 |
| **Documentation** | None |
| **Stats/Mean** | [0.45, 0.449, 0.295] |
| **Stats/Standard Deviation** | [0.231, 0.228, 0.23] |


## Examples
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/sample_images/tomato_leaf_disease_examples.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/sample_images/vine_virus_photo_dataset_examples.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions scripts/generate_dataset_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ def build_table(json):
return table


# def generate_example_images(name):
# """Generates the example images for the given dataset."""
# agml.backend.set_seed(189)
# loader = agml.data.AgMLDataLoader(name)
# return agml.viz.show_sample(loader, no_show = True)

def generate_example_images(name):
"""Generates the example images for the given dataset."""
"""Generates multiple example images for the given dataset."""
agml.backend.set_seed(189)
loader = agml.data.AgMLDataLoader(name)
return agml.viz.show_sample(loader, no_show = True)
loader = agml.data.AgMLDataLoader(name, batch_size=4) # Ensure the batch size is correct
return agml.viz.show_sample(loader, num_images=4, no_show=True)


def build_examples(name):
Expand Down

0 comments on commit 7b971cb

Please sign in to comment.