bilaljawaid980 commited on
Commit ·
1c28b5d
0
Parent(s):
Final cleanup and public release of GRIP-Benchmark-34
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +28 -0
- .gitignore +10 -0
- All question and answer/all_answers_combined.csv +3 -0
- All question and answer/all_questions_combined.csv +3 -0
- Dataset/angle_estimation_dataset_3000/README.md +46 -0
- Dataset/angle_estimation_dataset_3000/annotations.jsonl +0 -0
- Dataset/angle_estimation_dataset_3000/answer_key.csv +0 -0
- Dataset/angle_estimation_dataset_3000/build_manifest.json +23 -0
- Dataset/angle_estimation_dataset_3000/dataset_final.csv +0 -0
- Dataset/angle_estimation_dataset_3000/dataset_final.jsonl +0 -0
- Dataset/angle_estimation_dataset_3000/flatten_annotations.py +22 -0
- Dataset/angle_estimation_dataset_3000/generate_angle_estimation_dataset.py +115 -0
- Dataset/angle_estimation_dataset_3000/generation_stats.json +5 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0001.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0002.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0003.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0004.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0005.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0006.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0007.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0008.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0009.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0010.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0011.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0012.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0013.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0014.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0015.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0016.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0017.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0018.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0019.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0020.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0021.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0022.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0023.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0024.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0025.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0026.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0027.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0028.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0029.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0030.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0031.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0032.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0033.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0034.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0035.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0036.png +3 -0
- Dataset/angle_estimation_dataset_3000/images/angle_estimation_0037.png +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
All[[:space:]]question[[:space:]]and[[:space:]]answer/all_answers_combined.csv filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
All[[:space:]]question[[:space:]]and[[:space:]]answer/all_questions_combined.csv filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
Dataset/cube_structure_dataset_3000/dataset_final.csv filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
Dataset/cube_structure_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
Dataset/fbd_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
Dataset/fbd_dataset_3000/dataset_final.csv filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
Dataset/fbd_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
Dataset/gauge_reading_dataset_3000/dataset_final.csv filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
Dataset/gauge_reading_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
Dataset/hex_pathfinding_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
Dataset/impossible_object_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
Dataset/laser_mirror_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
Dataset/nested_hexagons_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
Dataset/nested_hexagons_dataset_3000/dataset_final.csv filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
Dataset/nested_hexagons_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
Dataset/nested_squares_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
Dataset/nested_squares_dataset_3000/dataset_final.csv filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
Dataset/nested_squares_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
Dataset/nested_triangles_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
Dataset/nested_triangles_dataset_3000/dataset_final.csv filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
Dataset/nested_triangles_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
Dataset/optical_illusion_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
Dataset/overlap_circles_dataset_3000/dataset_final.csv filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
Dataset/overlap_circles_dataset_3000/dataset_final.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
Dataset/physical_stability_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
Dataset/rpm_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
Dataset/surface_topology_dataset_3000/annotations.jsonl filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.py[cod]
|
| 3 |
+
.pytest_cache/
|
| 4 |
+
.git-*.log
|
| 5 |
+
.env
|
| 6 |
+
.hf_cache/
|
| 7 |
+
hf_upload_verification/
|
| 8 |
+
.vscode/
|
| 9 |
+
sample_test/
|
| 10 |
+
preflight_v2/
|
All question and answer/all_answers_combined.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3d06b4fb8c938d023afd0124441aff4f49086c7fb1732a7e087a0be481a759f8
|
| 3 |
+
size 94055165
|
All question and answer/all_questions_combined.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:266e25acd56751f628698aa6115e175361d8f04b13f4468b71823d2e79cbdc77
|
| 3 |
+
size 88236085
|
Dataset/angle_estimation_dataset_3000/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Angle Estimation Dataset (3,000 images)
|
| 2 |
+
|
| 3 |
+
## 1. Dataset purpose
|
| 4 |
+
|
| 5 |
+
This dataset fills a gap in the existing spatial-reasoning suite: no earlier category directly tests angle measurement, despite angle judgment being foundational to classical plane geometry. It covers marked single angles, angle comparison independent of ray length, and triangle-angle classification.
|
| 6 |
+
|
| 7 |
+
For comparison-scene Level 4, the public rule is explicit: `right` means within 15° of 90°, `straight` means within 15° of 180°, and all other sums are `neither`. Generation keeps sums at least 2° away from either decision boundary and balances these three outcomes.
|
| 8 |
+
|
| 9 |
+
## 2. Visual design
|
| 10 |
+
|
| 11 |
+
Every 450–500 px dark-theme image contains one of three scenes. Single scenes show two rays and an orange arc that disambiguates the selected minor or reflex sweep. Comparison scenes place two independently sized angles side by side. Triangle scenes show labeled vertices and marked interior arcs. Thin teal geometry, orange arcs, and coral vertices provide consistent technical-diagram styling.
|
| 12 |
+
|
| 13 |
+
## 3. Ground-truth construction
|
| 14 |
+
|
| 15 |
+
All measures are computed from stored coordinates using the dot-product formula `acos((u·v)/(|u||v|))`. Reflex single angles are represented as `360° − minor_angle` and explicitly marked by the long arc. Triangle angles are independently computed at A, B, and C and must sum to 180°. Dataset composition is 40% single, 35% comparison, and 25% triangle; triangle classes are exactly balanced.
|
| 16 |
+
|
| 17 |
+
The supplied Level 1 single-angle template defines “obtuse” as any marked angle greater than 90°, so reflex marked sweeps follow that benchmark-specific bucket even though classical geometry normally treats reflex as a separate category.
|
| 18 |
+
|
| 19 |
+
## 4. Questions and outputs
|
| 20 |
+
|
| 21 |
+
Each image has four ordered questions covering description/classification, core angle estimation or comparison, structural reasoning, and compound/theorem reasoning. `annotations.jsonl` preserves all coordinates and exact measures. `dataset_final.csv` and `dataset_final.jsonl` provide 12,000 flattened rows.
|
| 22 |
+
|
| 23 |
+
## 5. Generation and reproducibility
|
| 24 |
+
|
| 25 |
+
Python 3 and Pillow are required. Image `i` uses `random.Random(i)`.
|
| 26 |
+
|
| 27 |
+
```powershell
|
| 28 |
+
python generate_angle_estimation_dataset.py --n 3000 --output-dir .
|
| 29 |
+
python flatten_annotations.py --dataset-dir .
|
| 30 |
+
python make_contact_sheet.py --dataset-dir . --output contact_sheet.png --count 20 --columns 5
|
| 31 |
+
python make_contact_sheet.py --dataset-dir . --output human_calibration/review_sheet.png --count 5 --columns 5
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
Use `--sample` for five varied development examples.
|
| 35 |
+
|
| 36 |
+
## 6. Validation
|
| 37 |
+
|
| 38 |
+
```powershell
|
| 39 |
+
python validate_angle_dataset.py --dataset-dir . --report validation_report.txt
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
The validator independently recomputes every angle from coordinates, verifies reflex conversion, enforces comparison separation, checks triangle sums/classes/extrema, re-derives every answer, audits distributions, and reads every PNG to sample the expected ray segments, marked arc sweep, and triangle edges.
|
| 43 |
+
|
| 44 |
+
## 7. Known limitations
|
| 45 |
+
|
| 46 |
+
Nearest-15-degree estimation has intentional tolerance rather than requiring pixel-perfect reading. Triangle classification uses a ±2° right-angle band. Scenes are clean synthetic line drawings without perspective or hand-drawn distortion. The Level 1 bucket follows the provided greater-than-90° wording for reflex angles.
|
Dataset/angle_estimation_dataset_3000/annotations.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Dataset/angle_estimation_dataset_3000/answer_key.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Dataset/angle_estimation_dataset_3000/build_manifest.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"constraint_source": "generator constants and validation metrics",
|
| 3 |
+
"current_build_layout": "unsuffixed",
|
| 4 |
+
"dataset_version": "angle-estimation-3.0.0",
|
| 5 |
+
"generator_commit": "269045bc25630d3cc96a3d617e35043d72f941cd",
|
| 6 |
+
"images": 3000,
|
| 7 |
+
"constraints": {
|
| 8 |
+
"angle_sum_boundary_margin_degrees": 2,
|
| 9 |
+
"angle_sum_threshold_degrees": 15,
|
| 10 |
+
"comparison_level4_balance": {
|
| 11 |
+
"neither": 350,
|
| 12 |
+
"right": 350,
|
| 13 |
+
"straight": 350
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"question_set_fields": [
|
| 17 |
+
"question_id",
|
| 18 |
+
"task",
|
| 19 |
+
"image",
|
| 20 |
+
"prompt"
|
| 21 |
+
],
|
| 22 |
+
"questions": 15000
|
| 23 |
+
}
|
Dataset/angle_estimation_dataset_3000/dataset_final.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Dataset/angle_estimation_dataset_3000/dataset_final.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Dataset/angle_estimation_dataset_3000/flatten_annotations.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse,csv,json
|
| 2 |
+
from collections import Counter
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
TASKS={1:'Image Description',2:'Angle Estimation',3:'Structural Reasoning',4:'Compound Reasoning'};META=('difficulty_score','scene_type','canvas_size','seed')
|
| 5 |
+
def flatten(root):
|
| 6 |
+
root=Path(root);rows=[];images=0;bad=[]
|
| 7 |
+
for line in (root/'annotations.jsonl').open(encoding='utf8'):
|
| 8 |
+
item=json.loads(line);images+=1;qs=item.get('questions',[])
|
| 9 |
+
if len(qs)!=4:bad.append(item['id'])
|
| 10 |
+
metadata=json.dumps({k:item[k] for k in META},separators=(',',':'))
|
| 11 |
+
for q in qs:rows.append({'task':TASKS[q['difficulty_level']],'image':Path(item['image_path']).name,'prompt':q['question_text'],'groundtruth':str(q['ground_truth']),'metadata':metadata})
|
| 12 |
+
fields=('task','image','prompt','groundtruth','metadata')
|
| 13 |
+
with (root/'dataset_final.csv').open('w',encoding='utf-8-sig',newline='') as f:w=csv.DictWriter(f,fieldnames=fields);w.writeheader();w.writerows(rows)
|
| 14 |
+
with (root/'dataset_final.jsonl').open('w',encoding='utf8',newline='\n') as f:
|
| 15 |
+
for row in rows:f.write(json.dumps(row,separators=(',',':'))+'\n')
|
| 16 |
+
with (root/'dataset_final.csv').open(encoding='utf-8-sig',newline='') as f:readback=sum(1 for _ in csv.DictReader(f))
|
| 17 |
+
counts=Counter(r['task'] for r in rows);print(f'Images read: {images}\nTotal rows written: {len(rows)}\nCSV rows re-read: {readback}')
|
| 18 |
+
for task,count in sorted(counts.items()):print(f'{task}: {count}')
|
| 19 |
+
print('Images without exactly 4 questions: '+(', '.join(bad) if bad else 'none'))
|
| 20 |
+
if readback!=images*4 or bad:raise SystemExit(1)
|
| 21 |
+
def main():p=argparse.ArgumentParser();p.add_argument('--dataset-dir',default='.');flatten(p.parse_args().dataset_dir)
|
| 22 |
+
if __name__=='__main__':main()
|
Dataset/angle_estimation_dataset_3000/generate_angle_estimation_dataset.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Generate deterministic plane-geometry angle-estimation images."""
|
| 2 |
+
import argparse,json,math,random
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from PIL import Image,ImageDraw,ImageFont
|
| 5 |
+
|
| 6 |
+
BG=(26,26,26);RAY=(83,190,205);ARC=(242,174,75);INK=(226,230,230);POINT=(239,118,129);AA=3
|
| 7 |
+
ANGLE_SUM_TOLERANCE=15;ANGLE_SUM_BOUNDARY_MARGIN=2
|
| 8 |
+
DATASET_VERSION='angle-estimation-3.0.0';COMPARISON_REJECTIONS=0
|
| 9 |
+
|
| 10 |
+
def compute_angle(vertex,p1,p2):
|
| 11 |
+
a=(p1[0]-vertex[0],p1[1]-vertex[1]);b=(p2[0]-vertex[0],p2[1]-vertex[1]);dot=a[0]*b[0]+a[1]*b[1];den=math.hypot(*a)*math.hypot(*b);return math.degrees(math.acos(max(-1,min(1,dot/den))))
|
| 12 |
+
def marked_angle(vertex,p1,p2,reflex):
|
| 13 |
+
minor=compute_angle(vertex,p1,p2);return 360-minor if reflex else minor
|
| 14 |
+
def triangle_angles(vertices):
|
| 15 |
+
a,b,c=vertices;return [compute_angle(a,b,c),compute_angle(b,a,c),compute_angle(c,a,b)]
|
| 16 |
+
def nearest(value,step):return int(math.floor(value/step+.5)*step)
|
| 17 |
+
def class90(value,tol=2):return 'right' if abs(value-90)<=tol else 'acute' if value<90 else 'obtuse'
|
| 18 |
+
def font(size,bold=False):
|
| 19 |
+
p=Path('C:/Windows/Fonts/arialbd.ttf' if bold else 'C:/Windows/Fonts/arial.ttf');return ImageFont.truetype(str(p),size) if p.exists() else ImageFont.load_default()
|
| 20 |
+
def line(draw,points,fill,width=1.2):draw.line([(round(x*AA),round(y*AA)) for x,y in points],fill=fill,width=max(2,round(width*AA)),joint='curve')
|
| 21 |
+
def draw_arc(draw,vertex,start,sweep,radius):
|
| 22 |
+
theta=math.atan2(start[1]-vertex[1],start[0]-vertex[0]);points=[];steps=max(18,round(abs(sweep)/4))
|
| 23 |
+
for i in range(steps+1):
|
| 24 |
+
a=theta+math.radians(sweep)*i/steps;points.append((vertex[0]+radius*math.cos(a),vertex[1]+radius*math.sin(a)))
|
| 25 |
+
line(draw,points,ARC,1.35)
|
| 26 |
+
def draw_angle(draw,vertex,p1,p2,sweep,label=None):
|
| 27 |
+
line(draw,[vertex,p1],RAY,1.25);line(draw,[vertex,p2],RAY,1.25);r=min(math.dist(vertex,p1),math.dist(vertex,p2))*.23;draw_arc(draw,vertex,p1,sweep,r);x,y=vertex;rr=3;draw.ellipse(((x-rr)*AA,(y-rr)*AA,(x+rr)*AA,(y+rr)*AA),fill=POINT)
|
| 28 |
+
if label:draw.text(((x+8)*AA,(y+8)*AA),label,font=font(10*AA,True),fill=INK)
|
| 29 |
+
|
| 30 |
+
def angle_geometry(center,measure,length1,length2,start_deg):
|
| 31 |
+
theta=math.radians(start_deg);p1=(center[0]+length1*math.cos(theta),center[1]+length1*math.sin(theta));theta2=theta+math.radians(measure);p2=(center[0]+length2*math.cos(theta2),center[1]+length2*math.sin(theta2));p1=tuple(round(v,4) for v in p1);p2=tuple(round(v,4) for v in p2);actual=marked_angle(center,p1,p2,measure>180);return p1,p2,actual
|
| 32 |
+
def safe_start(center,measure,lengths,box,rng):
|
| 33 |
+
for _ in range(1000):
|
| 34 |
+
start=rng.uniform(0,360);p1,p2,actual=angle_geometry(center,measure,*lengths,start);x0,y0,x1,y1=box
|
| 35 |
+
if all(x0<=p[0]<=x1 and y0<=p[1]<=y1 for p in (p1,p2)):return start,p1,p2,actual
|
| 36 |
+
raise RuntimeError('unable to place angle')
|
| 37 |
+
def choose_single_measure(i,rng):
|
| 38 |
+
if i%5==0:return float(rng.choice((30,45,60,90,120,180)))
|
| 39 |
+
while True:
|
| 40 |
+
value=rng.uniform(10,350)
|
| 41 |
+
if min(abs(value-k*90) for k in range(5))>6:return value
|
| 42 |
+
def single_scene(i,rng,size):
|
| 43 |
+
w,h=size;v=(w/2,h/2+12);m=choose_single_measure(i,rng);lengths=(rng.uniform(125,175),rng.uniform(105,165));start,p1,p2,actual=safe_start(v,m,lengths,(24,35,w-24,h-24),rng)
|
| 44 |
+
return {'angle_degrees':round(actual,6),'vertex':[round(x,4) for x in v],'ray_endpoints':[list(p1),list(p2)],'marked_sweep':'reflex' if actual>180 else 'minor','arc_sweep_degrees':round(actual,6)}
|
| 45 |
+
def angle_sum_bucket(total):return 'right' if abs(total-90)<=ANGLE_SUM_TOLERANCE else 'straight' if abs(total-180)<=ANGLE_SUM_TOLERANCE else 'neither'
|
| 46 |
+
def comparison_scene(i,rng,size):
|
| 47 |
+
global COMPARISON_REJECTIONS
|
| 48 |
+
w,h=size;occurrence=((i-1)//20)*7+((i-1)%20-8);target=('right','straight','neither')[occurrence%3]
|
| 49 |
+
while True:
|
| 50 |
+
measures=[rng.uniform(10,170),rng.uniform(10,170)];total=sum(measures);distances=(abs(total-90),abs(total-180))
|
| 51 |
+
if abs(measures[0]-measures[1])>=8 and all(abs(d-ANGLE_SUM_TOLERANCE)>=ANGLE_SUM_BOUNDARY_MARGIN for d in distances) and angle_sum_bucket(total)==target:break
|
| 52 |
+
COMPARISON_REJECTIONS+=1
|
| 53 |
+
data=[]
|
| 54 |
+
for j,(cx,m) in enumerate(((w*.27,measures[0]),(w*.73,measures[1]))):
|
| 55 |
+
v=(cx,h*.57);lengths=(rng.uniform(75,115),rng.uniform(105,145));start,p1,p2,actual=safe_start(v,m,lengths,(12+j*w/2,55,(j+1)*w/2-12,h-28),rng);data.append({'vertex':[round(x,4) for x in v],'ray_endpoints':[list(p1),list(p2)],'angle_degrees':round(actual,6),'arc_sweep_degrees':round(actual,6)})
|
| 56 |
+
return {'angles':data,'angle_1_degrees':data[0]['angle_degrees'],'angle_2_degrees':data[1]['angle_degrees'],'larger_angle':'Angle 1' if data[0]['angle_degrees']>data[1]['angle_degrees'] else 'Angle 2'}
|
| 57 |
+
def raw_triangle(target,rng):
|
| 58 |
+
for _ in range(5000):
|
| 59 |
+
a=(0.0,0.0);b=(rng.uniform(1.4,2.4),0.0)
|
| 60 |
+
if target=='right':alpha=90+rng.uniform(-1.1,1.1)
|
| 61 |
+
elif target=='acute':alpha=rng.uniform(42,75)
|
| 62 |
+
else:alpha=rng.uniform(98,140)
|
| 63 |
+
length=rng.uniform(1.0,2.2);c=(length*math.cos(math.radians(alpha)),-length*math.sin(math.radians(alpha)));angles=triangle_angles((a,b,c));klass='right' if any(abs(x-90)<=2 for x in angles) else 'acute' if max(angles)<90 else 'obtuse'
|
| 64 |
+
if klass==target and min(angles)>5 and max(angles)<170:return (a,b,c)
|
| 65 |
+
raise RuntimeError('triangle generation failed')
|
| 66 |
+
def triangle_scene(target,rng,size):
|
| 67 |
+
raw=raw_triangle(target,rng);xs=[p[0] for p in raw];ys=[p[1] for p in raw];w,h=size;scale=min((w-110)/(max(xs)-min(xs)),(h-100)/(max(ys)-min(ys)));cx=w/2;cy=h/2+15;verts=[]
|
| 68 |
+
for x,y in raw:verts.append((round(cx+(x-(min(xs)+max(xs))/2)*scale,4),round(cy+(y-(min(ys)+max(ys))/2)*scale,4)))
|
| 69 |
+
angles=triangle_angles(verts);labels='ABC';largest=labels[max(range(3),key=lambda j:angles[j])];smallest=labels[min(range(3),key=lambda j:angles[j])]
|
| 70 |
+
return {'triangle_vertices':[list(p) for p in verts],'interior_angles_degrees':[round(x,6) for x in angles],'triangle_class':target,'largest_angle_vertex':largest,'smallest_angle_vertex':smallest}
|
| 71 |
+
|
| 72 |
+
def render(path,size,scene_type,data):
|
| 73 |
+
w,h=size;im=Image.new('RGB',(w*AA,h*AA),BG);d=ImageDraw.Draw(im);d.text((15*AA,12*AA),{'single':'Marked angle','comparison':'Compare the marked angles','triangle':'Triangle angles'}[scene_type],font=font(14*AA,True),fill=INK)
|
| 74 |
+
if scene_type=='single':
|
| 75 |
+
v=tuple(data['vertex']);p1,p2=map(tuple,data['ray_endpoints']);draw_angle(d,v,p1,p2,data['arc_sweep_degrees'],'V')
|
| 76 |
+
elif scene_type=='comparison':
|
| 77 |
+
for j,a in enumerate(data['angles']):
|
| 78 |
+
v=tuple(a['vertex']);p1,p2=map(tuple,a['ray_endpoints']);draw_angle(d,v,p1,p2,a['arc_sweep_degrees']);d.text(((v[0]-32)*AA,43*AA),f'Angle {j+1}',font=font(12*AA,True),fill=INK)
|
| 79 |
+
line(d,[(w/2,52),(w/2,h-20)],(72,76,77),.6)
|
| 80 |
+
else:
|
| 81 |
+
vertices=list(map(tuple,data['triangle_vertices']));line(d,vertices+[vertices[0]],RAY,1.35)
|
| 82 |
+
for j,v in enumerate(vertices):
|
| 83 |
+
rr=3;d.ellipse(((v[0]-rr)*AA,(v[1]-rr)*AA,(v[0]+rr)*AA,(v[1]+rr)*AA),fill=POINT);d.text(((v[0]+7)*AA,(v[1]-17)*AA),'ABC'[j],font=font(11*AA,True),fill=INK)
|
| 84 |
+
prev=vertices[(j-1)%3];nxt=vertices[(j+1)%3];a1=math.atan2(prev[1]-v[1],prev[0]-v[0]);a2=math.atan2(nxt[1]-v[1],nxt[0]-v[0]);sweep=(math.degrees(a2-a1))%360
|
| 85 |
+
if sweep>180:sweep-=360
|
| 86 |
+
draw_arc(d,v,prev,sweep,22)
|
| 87 |
+
im.resize(size,Image.Resampling.LANCZOS).save(path,'PNG')
|
| 88 |
+
|
| 89 |
+
def questions(iid,scene,row):
|
| 90 |
+
if scene=='single':
|
| 91 |
+
a=row['angle_degrees'];texts=("Is the marked angle acute (less than 90°), right (exactly 90°), or obtuse (greater than 90°)? Answer with one word.","Estimate the measure of the marked angle, rounded to the nearest 15 degrees. Answer with a number in curly brackets, e.g. {45}.","Is the marked angle greater than, less than, or approximately equal to a right angle (90 degrees)?","How many degrees is the shown angle away from a straight angle, rounded to the nearest degree?","If this angle were doubled, would the result still be less than a straight angle (180 degrees), or would it exceed a straight angle?");types=('single_angle_class','single_angle_nearest_15','single_vs_right','distance_from_straight_angle','single_doubled');gts=(class90(a),str(nearest(a,15)),'approximately equal to' if abs(a-90)<=5 else 'less than' if a<90 else 'greater than',str(round(abs(a-180))),'less than 180' if a*2<180 else 'exceeds 180');fmts=('one_word',{'type':'numeric_tolerance','absolute_tolerance':5,'answer_key_side_only':True},'choice','numeric','choice')
|
| 92 |
+
elif scene=='comparison':
|
| 93 |
+
a,b=row['angle_1_degrees'],row['angle_2_degrees'];small,large=sorted((a,b));texts=("How many separate angles are shown in this image?","Which angle is larger, Angle 1 or Angle 2? Answer with the label.","Approximately how many degrees larger is the bigger angle compared to the smaller one, rounded to the nearest 10 degrees?","If Angle 1 and Angle 2 were added together, answer 'right angle' if the sum is within 15 degrees of 90°, 'straight angle' if it is within 15 degrees of 180°, otherwise answer 'neither'.","If the smaller shown angle were doubled, would it be larger than, equal to, or smaller than the other angle?");types=('shown_angle_count','larger_angle','angle_difference_nearest_10','angle_sum_bucket','double_smaller_angle_compare');gts=('2',row['larger_angle'],str(nearest(abs(a-b),10)),angle_sum_bucket(a+b),'larger' if 2*small>large else 'equal to' if abs(2*small-large)<1e-9 else 'smaller');fmts=('numeric','label',{'type':'numeric_tolerance','absolute_tolerance':5,'answer_key_side_only':True},'choice','choice')
|
| 94 |
+
else:
|
| 95 |
+
texts=("How many vertices does the triangle have?","Is this triangle acute, right, or obtuse? Answer with one word.","Which vertex of the triangle has the largest interior angle? Answer with the vertex label.","The three interior angles of any triangle have what fixed total? Answer with a number in curly brackets.","If the smallest interior angle increased by 10 degrees while the other two stayed fixed, what would the new angle sum be, and would it still form a Euclidean triangle? Answer as sum,yes/no.");types=('triangle_vertex_count','triangle_class','largest_triangle_angle','triangle_angle_sum','increase_triangle_angle_validity');gts=('3',row['triangle_class'],row['largest_angle_vertex'],'180','190,no');fmts=('numeric','one_word','label','numeric','numeric')
|
| 96 |
+
return [{'question_id':iid+f'_q{k+1}','question_text':texts[k],'question_type':types[k],'ground_truth':gts[k],'answer_format':fmts[k],'difficulty_level':k+1} for k in range(5)]
|
| 97 |
+
def scene_for(i):
|
| 98 |
+
slot=(i-1)%20;return 'single' if slot<8 else 'comparison' if slot<15 else 'triangle'
|
| 99 |
+
def generate_one(i,images):
|
| 100 |
+
rng=random.Random(i);size=(rng.randint(450,500),rng.randint(450,500));scene=scene_for(i)
|
| 101 |
+
if scene=='single':data=single_scene(i,rng,size)
|
| 102 |
+
elif scene=='comparison':data=comparison_scene(i,rng,size)
|
| 103 |
+
else:data=triangle_scene(('acute','right','obtuse')[((i-1)//20)%3],rng,size)
|
| 104 |
+
iid=f'angle_estimation_{i:04d}';render(images/f'{iid}.png',size,scene,data);row={'id':iid,'image_path':f'images/{iid}.png','canvas_size':list(size),'scene_type':scene,**data,'seed':i,'difficulty_score':round({'single':.44,'comparison':.55,'triangle':.62}[scene]+(.12 if scene=='single' and data['angle_degrees']>180 else 0),4),'dataset_version':DATASET_VERSION};row['questions']=questions(iid,scene,row);return row
|
| 105 |
+
def generate_dataset(n,output_dir,sample=False):
|
| 106 |
+
global COMPARISON_REJECTIONS
|
| 107 |
+
COMPARISON_REJECTIONS=0;root=Path(output_dir);images=root/'images';images.mkdir(parents=True,exist_ok=True);indices=(1,5,9,16,56) if sample else range(1,n+1);count=len(indices) if sample else n
|
| 108 |
+
with (root/'annotations.jsonl').open('w',encoding='utf8',newline='\n') as f:
|
| 109 |
+
for progress,i in enumerate(indices,1):
|
| 110 |
+
f.write(json.dumps(generate_one(i,images),sort_keys=True,separators=(',',':'))+'\n')
|
| 111 |
+
if progress%250==0 or progress==count:print(f'Generated {progress}/{count}',flush=True)
|
| 112 |
+
(root/'generation_stats.json').write_text(json.dumps({'angle_sum_threshold_degrees':ANGLE_SUM_TOLERANCE,'angle_sum_boundary_margin_degrees':ANGLE_SUM_BOUNDARY_MARGIN,'comparison_generation_rejections':COMPARISON_REJECTIONS},indent=2)+'\n',encoding='utf8')
|
| 113 |
+
def main():
|
| 114 |
+
p=argparse.ArgumentParser();p.add_argument('--n',type=int,default=3000);p.add_argument('--output-dir',default='.');p.add_argument('--sample',action='store_true');a=p.parse_args();generate_dataset(a.n,a.output_dir,a.sample)
|
| 115 |
+
if __name__=='__main__':main()
|
Dataset/angle_estimation_dataset_3000/generation_stats.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"angle_sum_threshold_degrees": 15,
|
| 3 |
+
"angle_sum_boundary_margin_degrees": 2,
|
| 4 |
+
"comparison_generation_rejections": 7310
|
| 5 |
+
}
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0001.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0002.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0003.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0004.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0005.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0006.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0007.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0008.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0009.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0010.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0011.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0012.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0013.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0014.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0015.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0016.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0017.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0018.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0019.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0020.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0021.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0022.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0023.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0024.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0025.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0026.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0027.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0028.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0029.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0030.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0031.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0032.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0033.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0034.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0035.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0036.png
ADDED
|
Git LFS Details
|
Dataset/angle_estimation_dataset_3000/images/angle_estimation_0037.png
ADDED
|
Git LFS Details
|