-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path3_viz_image_patterns.py
74 lines (56 loc) · 2.42 KB
/
3_viz_image_patterns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.brain as fob
"""
We now have the basic objects and app interface under our belt. Time to start doing real world work.
Let's start examining and prepping our data for analysis.
We are going to import an unlabeled set of images, calculate embeddings, and then explore what the embeddings
teach us about our data.
"""
PHOTO_DIR = "/photos"
DATASET_NAME = "photos"
# downloaded 443 public domain images from flickr, just images with no metadata. Load the data using the "directory of images" importer
# https://docs.voxel51.com/user_guide/dataset_creation/datasets.html#imagedirectory-import
dataset = fo.Dataset.from_dir(
dataset_dir=PHOTO_DIR,
dataset_type=fo.types.ImageDirectory,
name=DATASET_NAME,
overwrite=True,
persistent=True
)
# By default it uses mobilenet-v2-imagenet-torch"
# https://docs.voxel51.com/model_zoo/models.html#mobilenet-v2-imagenet-torch
# Trained on imagenet
fob.compute_visualization(dataset, embeddings="default_embed", brain_key="default_embed")
# Trained on 400 Million image text pairs from the internet
model = foz.load_zoo_model("open-clip-torch")
fob.compute_visualization(dataset, model=model, embeddings="open_clip_embed",
brain_key="openclip_embed")
# Based on a DETR model trainied on COCOA Data
model2 = foz.load_zoo_model("detection-transformer-torch")
fob.compute_visualization(dataset, model=model2, embeddings="det_transformer", brain_key="det_ransformer")
# trained on imagenet
# model2 = foz.load_zoo_model("mnasnet0.5-imagenet-torch")
# fob.compute_visualization(dataset, model=model2, embeddings="mnasnet_embed",
# brain_key="mnasnet_embed")
# Calculate representativness
# https://docs.voxel51.com/brain.html#image-representativeness
fob.compute_representativeness(dataset, progress=True)
# Calculate uniqueness
# https://docs.voxel51.com/brain.html#image-uniqueness
fob.compute_uniqueness(dataset, embeddings="open_clip_embed")
# Calculate near duplicates
# https://docs.voxel51.com/brain.html#near-duplicates
index = fob.compute_near_duplicates(
dataset,
embeddings="open_clip_embed",
# may need to change this distance measure for non-default mode: thresh=0.02,
)
duplicates_view = index.duplicates_view(
type_field="dup_type",
id_field="dup_id",
dist_field="dup_dist",
)
session = fo.launch_app(dataset)
session.wait()
print("done")