Skip to content

Commit

Permalink
Table with samples (#11)
Browse files Browse the repository at this point in the history
* done

* minor changes
  • Loading branch information
FrancescoSaverioZuppichini authored Nov 17, 2022
1 parent 4071199 commit 4daf170
Show file tree
Hide file tree
Showing 112 changed files with 212 additions and 41 deletions.
127 changes: 118 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

![rf100blog-mosaicthing](https://user-images.githubusercontent.com/15908060/202452898-9ca6b8f7-4805-4e8e-949a-6e080d7b94d2.jpg)

This repository implements the Roboflow 100 benchmark developed by [Roboflow](https://roboflow.com/). It contains code to download the dataset and reproduce
mAP values for YOLOv5 and YOLOv7 Fine-Tuning and GLIP Evaluation on 100 of Roboflow Universe
datasets.


## RF100

`RF100` contains the following datasets, carefully chosen from more than 90'000 datasets hosted on our [universe hub](https://universe.roboflow.com/). The datasets are splitted in 7 categories: `Aerial`, `Videogames`, `Microscopic`, `Underwater`, `Documents`, `Electromagnetic` and `Real World`.


| Category | Datasets | Images | Classes |
|-----------------|----------|---------|---------|
| Aerial | 7 | 9683 | 24 |
Expand All @@ -11,17 +21,10 @@
| Documents | 8 | 24813 | 90 |
| Electromagnetic | 12 | 36381 | 41 |
| Real World | 50 | 110615 | 495 |
| Total | 100 | 224,714 | 805 |
| **Total** | **100** | **224,714** | **805** |

This repository implements the Roboflow 100 benchmark developed by [Roboflow](https://roboflow.com/). It contains code to download the dataset and reproduce
mAP values for YOLOv5 and YOLOv7 Fine-Tuning and GLIP Evaluation on 100 of Roboflow Universe
datasets.

## RF100

`RF100` contains the following datasets, carefully chosen from more than 90'000 datasets hosted on our [universe hub](https://universe.roboflow.com/). The datasets are splitted in 7 categories: `Aerial`, `Videogames`, `Microscopic`, `Underwater`, `Documents`, `Electromagnetic` and `Real World`.

**TODO** create a table
🚨 **Head over the [Appendix](#appendix) at the bottom to see samples from each dataset**

We provide a [notebook to help you using RF100 with PyTorch](/notebooks/roboflow-100-pytorch.ipynb)

Expand Down Expand Up @@ -154,3 +157,109 @@ nvidia-docker run --gpus all --rm -it --ipc host --network host --shm-size 64g \
-v ${PWD}/datasets_links_640.txt:/workspace/datasets_links_640.txt \
rf100-benchmark ./GLIP-benchmark/train.sh
```


## Appendix

| dataset | samples |
|:------------------------------|:----------------------------------------------------------|
| hand-gestures-jps7z | ![alt](doc/images/grid/hand-gestures-jps7z.jpg) |
| smoke-uvylj | ![alt](doc/images/grid/smoke-uvylj.jpg) |
| wall-damage | ![alt](doc/images/grid/wall-damage.jpg) |
| corrosion-bi3q3 | ![alt](doc/images/grid/corrosion-bi3q3.jpg) |
| excavators-czvg9 | ![alt](doc/images/grid/excavators-czvg9.jpg) |
| chess-pieces-mjzgj | ![alt](doc/images/grid/chess-pieces-mjzgj.jpg) |
| road-signs-6ih4y | ![alt](doc/images/grid/road-signs-6ih4y.jpg) |
| street-work | ![alt](doc/images/grid/street-work.jpg) |
| construction-safety-gsnvb | ![alt](doc/images/grid/construction-safety-gsnvb.jpg) |
| road-traffic | ![alt](doc/images/grid/road-traffic.jpg) |
| washroom-rf1fa | ![alt](doc/images/grid/washroom-rf1fa.jpg) |
| circuit-elements | ![alt](doc/images/grid/circuit-elements.jpg) |
| mask-wearing-608pr | ![alt](doc/images/grid/mask-wearing-608pr.jpg) |
| cables-nl42k | ![alt](doc/images/grid/cables-nl42k.jpg) |
| soda-bottles | ![alt](doc/images/grid/soda-bottles.jpg) |
| truck-movement | ![alt](doc/images/grid/truck-movement.jpg) |
| wine-labels | ![alt](doc/images/grid/wine-labels.jpg) |
| digits-t2eg6 | ![alt](doc/images/grid/digits-t2eg6.jpg) |
| vehicles-q0x2v | ![alt](doc/images/grid/vehicles-q0x2v.jpg) |
| peanuts-sd4kf | ![alt](doc/images/grid/peanuts-sd4kf.jpg) |
| printed-circuit-board | ![alt](doc/images/grid/printed-circuit-board.jpg) |
| pests-2xlvx | ![alt](doc/images/grid/pests-2xlvx.jpg) |
| cavity-rs0uf | ![alt](doc/images/grid/cavity-rs0uf.jpg) |
| leaf-disease-nsdsr | ![alt](doc/images/grid/leaf-disease-nsdsr.jpg) |
| marbles | ![alt](doc/images/grid/marbles.jpg) |
| pills-sxdht | ![alt](doc/images/grid/pills-sxdht.jpg) |
| poker-cards-cxcvz | ![alt](doc/images/grid/poker-cards-cxcvz.jpg) |
| number-ops | ![alt](doc/images/grid/number-ops.jpg) |
| insects-mytwu | ![alt](doc/images/grid/insects-mytwu.jpg) |
| cotton-20xz5 | ![alt](doc/images/grid/cotton-20xz5.jpg) |
| furniture-ngpea | ![alt](doc/images/grid/furniture-ngpea.jpg) |
| cable-damage | ![alt](doc/images/grid/cable-damage.jpg) |
| animals-ij5d2 | ![alt](doc/images/grid/animals-ij5d2.jpg) |
| coins-1apki | ![alt](doc/images/grid/coins-1apki.jpg) |
| apples-fvpl5 | ![alt](doc/images/grid/apples-fvpl5.jpg) |
| people-in-paintings | ![alt](doc/images/grid/people-in-paintings.jpg) |
| circuit-voltages | ![alt](doc/images/grid/circuit-voltages.jpg) |
| uno-deck | ![alt](doc/images/grid/uno-deck.jpg) |
| grass-weeds | ![alt](doc/images/grid/grass-weeds.jpg) |
| gauge-u2lwv | ![alt](doc/images/grid/gauge-u2lwv.jpg) |
| sign-language-sokdr | ![alt](doc/images/grid/sign-language-sokdr.jpg) |
| valentines-chocolate | ![alt](doc/images/grid/valentines-chocolate.jpg) |
| fish-market-ggjso | ![alt](doc/images/grid/fish-market-ggjso.jpg) |
| lettuce-pallets | ![alt](doc/images/grid/lettuce-pallets.jpg) |
| shark-teeth-5atku | ![alt](doc/images/grid/shark-teeth-5atku.jpg) |
| bees-jt5in | ![alt](doc/images/grid/bees-jt5in.jpg) |
| sedimentary-features-9eosf | ![alt](doc/images/grid/sedimentary-features-9eosf.jpg) |
| currency-v4f8j | ![alt](doc/images/grid/currency-v4f8j.jpg) |
| trail-camera | ![alt](doc/images/grid/trail-camera.jpg) |
| cell-towers | ![alt](doc/images/grid/cell-towers.jpg) |
| apex-videogame | ![alt](doc/images/grid/apex-videogame.jpg) |
| farcry6-videogame | ![alt](doc/images/grid/farcry6-videogame.jpg) |
| csgo-videogame | ![alt](doc/images/grid/csgo-videogame.jpg) |
| avatar-recognition-nuexe | ![alt](doc/images/grid/avatar-recognition-nuexe.jpg) |
| halo-infinite-angel-videogame | ![alt](doc/images/grid/halo-infinite-angel-videogame.jpg) |
| team-fight-tactics | ![alt](doc/images/grid/team-fight-tactics.jpg) |
| robomasters-285km | ![alt](doc/images/grid/robomasters-285km.jpg) |
| tweeter-posts | ![alt](doc/images/grid/tweeter-posts.jpg) |
| tweeter-profile | ![alt](doc/images/grid/tweeter-profile.jpg) |
| document-parts | ![alt](doc/images/grid/document-parts.jpg) |
| activity-diagrams-qdobr | ![alt](doc/images/grid/activity-diagrams-qdobr.jpg) |
| signatures-xc8up | ![alt](doc/images/grid/signatures-xc8up.jpg) |
| paper-parts | ![alt](doc/images/grid/paper-parts.jpg) |
| tabular-data-wf9uh | ![alt](doc/images/grid/tabular-data-wf9uh.jpg) |
| paragraphs-co84b | ![alt](doc/images/grid/paragraphs-co84b.jpg) |
| underwater-pipes-4ng4t | ![alt](doc/images/grid/underwater-pipes-4ng4t.jpg) |
| aquarium-qlnqy | ![alt](doc/images/grid/aquarium-qlnqy.jpg) |
| peixos-fish | ![alt](doc/images/grid/peixos-fish.jpg) |
| underwater-objects-5v7p8 | ![alt](doc/images/grid/underwater-objects-5v7p8.jpg) |
| coral-lwptl | ![alt](doc/images/grid/coral-lwptl.jpg) |
| aerial-pool | ![alt](doc/images/grid/aerial-pool.jpg) |
| secondary-chains | ![alt](doc/images/grid/secondary-chains.jpg) |
| aerial-spheres | ![alt](doc/images/grid/aerial-spheres.jpg) |
| soccer-players-5fuqs | ![alt](doc/images/grid/soccer-players-5fuqs.jpg) |
| weed-crop-aerial | ![alt](doc/images/grid/weed-crop-aerial.jpg) |
| aerial-cows | ![alt](doc/images/grid/aerial-cows.jpg) |
| cloud-types | ![alt](doc/images/grid/cloud-types.jpg) |
| stomata-cells | ![alt](doc/images/grid/stomata-cells.jpg) |
| bccd-ouzjz | ![alt](doc/images/grid/bccd-ouzjz.jpg) |
| parasites-1s07h | ![alt](doc/images/grid/parasites-1s07h.jpg) |
| cells-uyemf | ![alt](doc/images/grid/cells-uyemf.jpg) |
| 4-fold-defect | ![alt](doc/images/grid/4-fold-defect.jpg) |
| bacteria-ptywi | ![alt](doc/images/grid/bacteria-ptywi.jpg) |
| cotton-plant-disease | ![alt](doc/images/grid/cotton-plant-disease.jpg) |
| mitosis-gjs3g | ![alt](doc/images/grid/mitosis-gjs3g.jpg) |
| phages | ![alt](doc/images/grid/phages.jpg) |
| liver-disease | ![alt](doc/images/grid/liver-disease.jpg) |
| asbestos | ![alt](doc/images/grid/asbestos.jpg) |
| thermal-dogs-and-people-x6ejw | ![alt](doc/images/grid/thermal-dogs-and-people-x6ejw.jpg) |
| solar-panels-taxvb | ![alt](doc/images/grid/solar-panels-taxvb.jpg) |
| radio-signal | ![alt](doc/images/grid/radio-signal.jpg) |
| thermal-cheetah-my4dp | ![alt](doc/images/grid/thermal-cheetah-my4dp.jpg) |
| x-ray-rheumatology | ![alt](doc/images/grid/x-ray-rheumatology.jpg) |
| acl-x-ray | ![alt](doc/images/grid/acl-x-ray.jpg) |
| abdomen-mri | ![alt](doc/images/grid/abdomen-mri.jpg) |
| axial-mri | ![alt](doc/images/grid/axial-mri.jpg) |
| gynecology-mri | ![alt](doc/images/grid/gynecology-mri.jpg) |
| brain-tumor-m2pbp | ![alt](doc/images/grid/brain-tumor-m2pbp.jpg) |
| bone-fracture-7fylg | ![alt](doc/images/grid/bone-fracture-7fylg.jpg) |
| flir-camera-objects | ![alt](doc/images/grid/flir-camera-objects.jpg) |
Binary file added doc/images/grid/4-fold-defect.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/abdomen-mri.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/acl-x-ray.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/activity-diagrams-qdobr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/aerial-cows.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/aerial-pool.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/aerial-spheres.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/animals-ij5d2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/apex-videogame.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/apples-fvpl5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/aquarium-qlnqy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/asbestos.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/avatar-recognition-nuexe.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/axial-mri.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/bacteria-ptywi.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/bccd-ouzjz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/bees-jt5in.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/bone-fracture-7fylg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/brain-tumor-m2pbp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/cable-damage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/cables-nl42k.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/cavity-rs0uf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/cell-towers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/cells-uyemf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/chess-pieces-mjzgj.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/grid/circuit-elements.jpg
Binary file added doc/images/grid/circuit-voltages.jpg
Binary file added doc/images/grid/cloud-types.jpg
Binary file added doc/images/grid/coins-1apki.jpg
Binary file added doc/images/grid/construction-safety-gsnvb.jpg
Binary file added doc/images/grid/coral-lwptl.jpg
Binary file added doc/images/grid/corrosion-bi3q3.jpg
Binary file added doc/images/grid/cotton-20xz5.jpg
Binary file added doc/images/grid/cotton-plant-disease.jpg
Binary file added doc/images/grid/csgo-videogame.jpg
Binary file added doc/images/grid/currency-v4f8j.jpg
Binary file added doc/images/grid/digits-t2eg6.jpg
Binary file added doc/images/grid/document-parts.jpg
Binary file added doc/images/grid/excavators-czvg9.jpg
Binary file added doc/images/grid/farcry6-videogame.jpg
Binary file added doc/images/grid/fish-market-ggjso.jpg
Binary file added doc/images/grid/flir-camera-objects.jpg
Binary file added doc/images/grid/furniture-ngpea.jpg
Binary file added doc/images/grid/gauge-u2lwv.jpg
Binary file added doc/images/grid/grass-weeds.jpg
Binary file added doc/images/grid/gynecology-mri.jpg
Binary file added doc/images/grid/hand-gestures-jps7z.jpg
Binary file added doc/images/grid/insects-mytwu.jpg
Binary file added doc/images/grid/leaf-disease-nsdsr.jpg
Binary file added doc/images/grid/lettuce-pallets.jpg
Binary file added doc/images/grid/liver-disease.jpg
Binary file added doc/images/grid/marbles.jpg
Binary file added doc/images/grid/mask-wearing-608pr.jpg
Binary file added doc/images/grid/mitosis-gjs3g.jpg
Binary file added doc/images/grid/number-ops.jpg
Binary file added doc/images/grid/paper-parts.jpg
Binary file added doc/images/grid/paragraphs-co84b.jpg
Binary file added doc/images/grid/parasites-1s07h.jpg
Binary file added doc/images/grid/peanuts-sd4kf.jpg
Binary file added doc/images/grid/peixos-fish.jpg
Binary file added doc/images/grid/people-in-paintings.jpg
Binary file added doc/images/grid/pests-2xlvx.jpg
Binary file added doc/images/grid/phages.jpg
Binary file added doc/images/grid/pills-sxdht.jpg
Binary file added doc/images/grid/poker-cards-cxcvz.jpg
Binary file added doc/images/grid/printed-circuit-board.jpg
Binary file added doc/images/grid/radio-signal.jpg
Binary file added doc/images/grid/road-signs-6ih4y.jpg
Binary file added doc/images/grid/road-traffic.jpg
Binary file added doc/images/grid/robomasters-285km.jpg
Binary file added doc/images/grid/secondary-chains.jpg
Binary file added doc/images/grid/sedimentary-features-9eosf.jpg
Binary file added doc/images/grid/shark-teeth-5atku.jpg
Binary file added doc/images/grid/sign-language-sokdr.jpg
Binary file added doc/images/grid/signatures-xc8up.jpg
Binary file added doc/images/grid/smoke-uvylj.jpg
Binary file added doc/images/grid/soccer-players-5fuqs.jpg
Binary file added doc/images/grid/soda-bottles.jpg
Binary file added doc/images/grid/solar-panels-taxvb.jpg
Binary file added doc/images/grid/stomata-cells.jpg
Binary file added doc/images/grid/street-work.jpg
Binary file added doc/images/grid/tabular-data-wf9uh.jpg
Binary file added doc/images/grid/team-fight-tactics.jpg
Binary file added doc/images/grid/thermal-cheetah-my4dp.jpg
Binary file added doc/images/grid/thermal-dogs-and-people-x6ejw.jpg
Binary file added doc/images/grid/trail-camera.jpg
Binary file added doc/images/grid/truck-movement.jpg
Binary file added doc/images/grid/tweeter-posts.jpg
Binary file added doc/images/grid/tweeter-profile.jpg
Binary file added doc/images/grid/underwater-objects-5v7p8.jpg
Binary file added doc/images/grid/underwater-pipes-4ng4t.jpg
Binary file added doc/images/grid/uno-deck.jpg
Binary file added doc/images/grid/valentines-chocolate.jpg
Binary file added doc/images/grid/vehicles-q0x2v.jpg
Binary file added doc/images/grid/wall-damage.jpg
Binary file added doc/images/grid/washroom-rf1fa.jpg
Binary file added doc/images/grid/weed-crop-aerial.jpg
Binary file added doc/images/grid/wine-labels.jpg
Binary file added doc/images/grid/x-ray-rheumatology.jpg
3 changes: 2 additions & 1 deletion scripts/convert_table_from_old_flo_paper_to_csv.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
Poor man script to convert the table from an old version of the paper. This was the only way since we didn't have access to the original data source from the table
"""
from pathlib import Path
from argparse import ArgumentParser
from pathlib import Path

import pandas as pd

parser = ArgumentParser()
Expand Down
1 change: 1 addition & 0 deletions scripts/download_dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from argparse import ArgumentParser
from os import environ
from pathlib import Path

from roboflow import Roboflow


Expand Down
5 changes: 3 additions & 2 deletions scripts/get_labels_names.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import requests
from concurrent.futures import ThreadPoolExecutor
from pprint import pprint

import pandas as pd
import requests
from tqdm import tqdm
from pprint import pprint

ROBOFLOW_API_KEY = os.environ["ROBOFLOW_API_KEY"]
API_URL = "https://api.roboflow.com/roboflow-100"
Expand Down
18 changes: 9 additions & 9 deletions scripts/image/cluster.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import numpy as np
from pickle import load, dump
from multiprocessing import Pool
from pathlib import Path
from tqdm import tqdm
from pickle import dump, load

import numpy as np
import pandas as pd
import torch
from torchvision.utils import make_grid
import torchvision.transforms as T
from torchvision.transforms.functional import to_pil_image
import pandas as pd
from PIL import Image
from multiprocessing import Pool

from kmeans import kmeans
from PIL import Image
from torchvision.transforms.functional import to_pil_image
from torchvision.utils import make_grid
from tqdm import tqdm

NUM_CLUSTERS = 32 * 56

Expand Down
12 changes: 6 additions & 6 deletions scripts/image/encode.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# read images from rf100
# encode them with clip

from pathlib import Path
from pickle import dump
from typing import Callable, Optional
import torch

import clip
from PIL import Image
from pathlib import Path
import numpy as np
import torch
import torch as nn
from torch.utils.data import Dataset, DataLoader
from PIL import Image
import numpy as np
from torch.utils.data import DataLoader, Dataset
from torchvision.transforms import ToTensor
from pickle import dump
from tqdm import tqdm

device = "cuda" if torch.cuda.is_available() else "cpu"
Expand Down
2 changes: 1 addition & 1 deletion scripts/image/kmeans.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
from einops import rearrange, repeat
import torch.nn.functional as F
from einops import rearrange, repeat
from tqdm import tqdm


Expand Down
57 changes: 57 additions & 0 deletions scripts/make_dataset_table_with_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Code to generate the markdown table in the README.md
"""
import random
from pathlib import Path
from typing import Tuple

import pandas as pd
import torch
from PIL import Image
from torchvision.transforms.functional import pil_to_tensor, to_pil_image
from torchvision.utils import make_grid

ROOT = Path("./rf100")


def read_and_transform(image_path: Path) -> torch.Tensor:
image = Image.open(image_path).convert("RGB").resize((128, 128))
return pil_to_tensor(image)


def make_grid_from_dataset(dataset_dir: Path, n=5) -> Tuple[str, Image.Image]:
# get random 5 images
images_paths = list((dataset_dir / "train" / "images").glob("*"))
sampled_images_paths = random.choices(images_paths, k=n)
tensors = [read_and_transform(image_path) for image_path in sampled_images_paths]
grid = make_grid(tensors, nrow=n)
return dataset_dir.stem, to_pil_image(grid)


def save(dataset_name: str, grid: Image.Image) -> Tuple[str, str]:
grid_path = f"doc/images/grid/{dataset_name}.jpg"
# grid.save(grid_path, quality=70)
return dataset_name, grid_path


def make_grids(root: Path):
out = list(map(make_grid_from_dataset, root.iterdir()))
out = list(map(lambda x: save(*x), out))
return out


def make_table(root: Path) -> str:
out = make_grids(root)
dataset_names, grid_paths = zip(*out)
category_df = pd.read_csv("metadata/categories.csv", index_col=0)
df = pd.DataFrame(
data=dict(dataset=dataset_names, samples=grid_paths),
columns=["dataset", "samples"],
)
df.samples = df.samples.apply(lambda x: f"![alt]({x})")
df = df.set_index("dataset", drop=True)
df = category_df.join(df)
del df["category"]
return df.to_markdown()


print(make_table(ROOT))
1 change: 1 addition & 0 deletions scripts/make_results_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
from textwrap import indent
from unicodedata import name

import pandas as pd

RF100_BASE_URL = "https://app.roboflow.com/roboflow-100"
Expand Down
3 changes: 2 additions & 1 deletion scripts/parse_categories.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
This script takes a file text (lost in time) and outputs a correctly formated csv file with category -> dataset
"""
import re
from argparse import ArgumentParser
from pathlib import Path

import pandas as pd
import re

parser = ArgumentParser()
parser.add_argument("-i", "--input", type=Path)
Expand Down
10 changes: 5 additions & 5 deletions scripts/reduce_dims.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict, Iterator, Tuple, List
from image.pca import pca
from pathlib import Path
from tqdm import tqdm
from pickle import load, dump
from pickle import dump, load
from typing import Dict, Iterator, List, Tuple

import numpy as np
import torch

from image.pca import pca
from sklearn.manifold import TSNE
from tqdm import tqdm


def get_data(root: Path) -> dict:
Expand Down
14 changes: 7 additions & 7 deletions scripts/split_for_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
This script will split the reduced-* pickle file into folders with the right dimension and metadata for the collage.
"""

import json
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from typing import Iterable, Tuple, List
from tqdm import tqdm
from pickle import load, dump
from pickle import dump, load
from typing import Iterable, List, Tuple

import numpy as np
from concurrent.futures import ThreadPoolExecutor
from PIL import Image
import json
from tqdm import tqdm

"""
1) read the data
Expand Down Expand Up @@ -90,7 +91,7 @@ def get_data_chunks(

def make_split(
data: dict, output_dir: Path, montage_size: str, image_size: str, *args, **kwargs
):
):
"""
Takes `data`, writes to disk all the images and the embeddings in json format
"""
Expand All @@ -113,7 +114,6 @@ def make_split(
)



def make_splits_by_dataset(
data: dict, output_dir: Path, montage_size: str, image_size: str, **kwargs
) -> List[dict]:
Expand Down

0 comments on commit 4daf170

Please sign in to comment.