Datasets:

Modalities:
Image
Languages:
English
DOI:
License:
mariateresadrp commited on
Commit
ce53c66
·
verified ·
1 Parent(s): 44d7fc8

Delete latentcanon--histvis.py"

Browse files
Files changed (1) hide show
  1. latentcanon--histvis.py/" +0 -100
latentcanon--histvis.py/" DELETED
@@ -1,100 +0,0 @@
1
- from datasets import load_dataset
2
- import matplotlib.pyplot as plt
3
- import pandas as pd
4
-
5
- # Method 1: Load dataset using the custom loading script
6
- # This assumes you've placed histvis_loading.py in your repo
7
- histvis = load_dataset("./", script_files=["histvis_loading.py"])
8
- print(f"Dataset loaded with {len(histvis['train'])} examples")
9
-
10
- # Method 2: Load directly from Hugging Face (once the loading script is added to the repo)
11
- # histvis = load_dataset("latentcanon/HistVis")
12
-
13
- # Display dataset info
14
- print("\nDataset Features:")
15
- print(histvis['train'].features)
16
-
17
- # Show some basic statistics
18
- print("\nHistorical periods in the dataset:")
19
- periods = histvis['train'].unique('historical_period')
20
- print(periods)
21
-
22
- print("\nModels in the dataset:")
23
- models = histvis['train'].unique('model')
24
- print(models)
25
-
26
- print("\nCategories in the dataset:")
27
- categories = histvis['train'].unique('category')
28
- print(categories)
29
-
30
- # Let's see a specific example
31
- example = histvis['train'][0]
32
- print("\nExample entry:")
33
- for key, value in example.items():
34
- if key != 'image': # Skip printing the image data
35
- print(f"{key}: {value}")
36
-
37
- # Display an image from the dataset
38
- plt.figure(figsize=(10, 10))
39
- plt.imshow(example['image'])
40
- plt.title(f"{example['historical_period']}: {example['universal_human_activity']}")
41
- plt.axis('off')
42
- plt.show()
43
-
44
- # Filter images by historical period and category
45
- filtered = histvis['train'].filter(lambda x:
46
- x['historical_period'] == '19th_century' and
47
- x['category'] == 'Art')
48
- print(f"\nFound {len(filtered)} images from 19th century in Art category")
49
-
50
- # Compare models for the same activity
51
- def compare_models_for_activity(dataset, activity, period=None):
52
- """Display images from different models for the same activity"""
53
- filter_fn = lambda x: x['universal_human_activity'] == activity
54
- if period:
55
- filter_fn = lambda x: x['universal_human_activity'] == activity and x['historical_period'] == period
56
-
57
- filtered = dataset.filter(filter_fn)
58
-
59
- if len(filtered) == 0:
60
- print(f"No images found for activity: {activity}")
61
- return
62
-
63
- # Get one example from each model
64
- model_examples = {}
65
- for item in filtered:
66
- if item['model'] not in model_examples:
67
- model_examples[item['model']] = item
68
-
69
- if len(model_examples) == 3: # Assuming 3 models
70
- break
71
-
72
- # Plot the examples
73
- fig, axes = plt.subplots(1, len(model_examples), figsize=(15, 5))
74
-
75
- for i, (model, item) in enumerate(model_examples.items()):
76
- if len(model_examples) == 1:
77
- ax = axes
78
- else:
79
- ax = axes[i]
80
-
81
- ax.imshow(item['image'])
82
- ax.set_title(f"Model: {model}")
83
- ax.axis('off')
84
-
85
- period_str = f" in {period}" if period else ""
86
- plt.suptitle(f"'{activity}'{period_str}")
87
- plt.tight_layout()
88
- plt.show()
89
-
90
- # Example usage
91
- compare_models_for_activity(histvis['train'], 'a person treating a wound with care', '21st_century')
92
-
93
- # Create a pandas DataFrame for easier analysis (excluding images)
94
- df = pd.DataFrame([
95
- {k: v for k, v in example.items() if k != 'image'}
96
- for example in histvis['train']
97
- ])
98
-
99
- print("\nDataset summary:")
100
- print(df.describe(include='all'))