prasatee commited on
Commit
6e6a3a7
·
verified ·
1 Parent(s): 8b312e5

Add files using upload-large-folder tool

Browse files
README.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ task_categories:
4
+ - image-segmentation
5
+ - object-detection
6
+ tags:
7
+ - P&ID
8
+ - lines
9
+ - pipelines
10
+ - engineering
11
+ - diagrams
12
+ - line-detection
13
+ size_categories:
14
+ - 1K<n<10K
15
+ ---
16
+
17
+ # P&ID Line Detection Dataset
18
+
19
+ This dataset contains cropped images from P&ID (Piping and Instrumentation Diagrams)
20
+ with line segment annotations for line detection and segmentation tasks.
21
+
22
+ ## Dataset Description
23
+
24
+ - **Total source images:** 500
25
+ - **Total cropped samples:** 10000
26
+ - **Total line segments:** 44754
27
+ - **Crops per image:** 20
28
+ - **Image sizes:** Various sizes under 1000px (e.g., 300x500, 512x768, 900x900)
29
+
30
+ ## Dataset Structure
31
+
32
+ Each sample contains:
33
+ - `file_name`: Image filename
34
+ - `source_image_idx`: Index of the original P&ID image
35
+ - `crop_idx`: Index of this crop from the source image
36
+ - `width`: Crop width in pixels
37
+ - `height`: Crop height in pixels
38
+ - `lines`: Dictionary with:
39
+ - `segments`: List of line segments as [x1, y1, x2, y2] (start and end points)
40
+ - `line_types`: List of line types ("solid" or "dashed")
41
+ - `pipelines`: List of pipeline names for each line
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ from datasets import load_dataset
47
+
48
+ # Load the dataset
49
+ dataset = load_dataset("imagefolder", data_dir="path/to/lines_dataset")
50
+
51
+ # Access a sample
52
+ sample = dataset["train"][0]
53
+ image = sample["image"]
54
+ lines = sample["lines"]
55
+ segments = lines["segments"] # [[x1, y1, x2, y2], ...]
56
+ line_types = lines["line_types"] # ["solid", "dashed", ...]
57
+ pipelines = lines["pipelines"] # ["5\"-EK-2648", ...]
58
+
59
+ # Draw lines on image
60
+ from PIL import ImageDraw
61
+ draw = ImageDraw.Draw(image)
62
+ for seg in segments:
63
+ x1, y1, x2, y2 = seg
64
+ draw.line([(x1, y1), (x2, y2)], fill="blue", width=3)
65
+ image.show()
66
+ ```
67
+
68
+ ## Line Segment Format
69
+
70
+ Each line segment is represented as `[x1, y1, x2, y2]` where:
71
+ - `(x1, y1)` is the start point
72
+ - `(x2, y2)` is the end point
73
+ - Coordinates are in pixels, relative to the cropped image
74
+ - Only lines where **both endpoints** are fully inside the crop are included
75
+
76
+ ## Line Types
77
+
78
+ - `solid`: Continuous pipeline lines
79
+ - `dashed`: Dashed lines (often representing signal/instrument lines)
80
+
81
+ ## License
82
+
83
+ MIT License
split_dataset.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Script to split the lines dataset into train/validation/test sets (80/10/10)
4
+ and transform the data format.
5
+ """
6
+
7
+ import json
8
+ import os
9
+ import shutil
10
+ import random
11
+ from pathlib import Path
12
+
13
+ # Set random seed for reproducibility
14
+ random.seed(42)
15
+
16
+ # Define paths
17
+ BASE_DIR = Path("/Users/prasatee/Desktop/unsloth/DigitizePID_Dataset/lines_dataset")
18
+ TRAIN_DIR = BASE_DIR / "train"
19
+ VAL_DIR = BASE_DIR / "validation"
20
+ TEST_DIR = BASE_DIR / "test"
21
+
22
+ # Read current metadata
23
+ metadata_path = TRAIN_DIR / "metadata.jsonl"
24
+ data = []
25
+
26
+ print("Reading metadata...")
27
+ with open(metadata_path, "r") as f:
28
+ for line in f:
29
+ entry = json.loads(line.strip())
30
+ # Transform to new format (flatten the "lines" field)
31
+ new_entry = {
32
+ "file_name": entry["file_name"],
33
+ "source_image_idx": entry["source_image_idx"],
34
+ "crop_idx": entry["crop_idx"],
35
+ "width": entry["width"],
36
+ "height": entry["height"],
37
+ "segments": entry["lines"]["segments"],
38
+ "line_types": entry["lines"]["line_types"],
39
+ "pipelines": entry["lines"]["pipelines"],
40
+ }
41
+ data.append(new_entry)
42
+
43
+ print(f"Total entries: {len(data)}")
44
+
45
+ # Shuffle data
46
+ random.shuffle(data)
47
+
48
+ # Calculate split sizes
49
+ total = len(data)
50
+ train_size = int(0.8 * total)
51
+ val_size = int(0.1 * total)
52
+ test_size = total - train_size - val_size
53
+
54
+ train_data = data[:train_size]
55
+ val_data = data[train_size:train_size + val_size]
56
+ test_data = data[train_size + val_size:]
57
+
58
+ print(f"Train: {len(train_data)}, Validation: {len(val_data)}, Test: {len(test_data)}")
59
+
60
+ # Create directories
61
+ VAL_DIR.mkdir(exist_ok=True)
62
+ TEST_DIR.mkdir(exist_ok=True)
63
+
64
+ print("\nMoving files...")
65
+
66
+ # Move validation files
67
+ print("Processing validation set...")
68
+ for entry in val_data:
69
+ src = TRAIN_DIR / entry["file_name"]
70
+ dst = VAL_DIR / entry["file_name"]
71
+ if src.exists():
72
+ shutil.move(str(src), str(dst))
73
+
74
+ # Move test files
75
+ print("Processing test set...")
76
+ for entry in test_data:
77
+ src = TRAIN_DIR / entry["file_name"]
78
+ dst = TEST_DIR / entry["file_name"]
79
+ if src.exists():
80
+ shutil.move(str(src), str(dst))
81
+
82
+ # Write new metadata files
83
+ print("\nWriting metadata files...")
84
+
85
+ # Train metadata
86
+ train_metadata_path = TRAIN_DIR / "metadata.jsonl"
87
+ with open(train_metadata_path, "w") as f:
88
+ for entry in train_data:
89
+ f.write(json.dumps(entry) + "\n")
90
+
91
+ # Validation metadata
92
+ val_metadata_path = VAL_DIR / "metadata.jsonl"
93
+ with open(val_metadata_path, "w") as f:
94
+ for entry in val_data:
95
+ f.write(json.dumps(entry) + "\n")
96
+
97
+ # Test metadata
98
+ test_metadata_path = TEST_DIR / "metadata.jsonl"
99
+ with open(test_metadata_path, "w") as f:
100
+ for entry in test_data:
101
+ f.write(json.dumps(entry) + "\n")
102
+
103
+ print("\nDone!")
104
+ print(f"Train set: {len(train_data)} samples in {TRAIN_DIR}")
105
+ print(f"Validation set: {len(val_data)} samples in {VAL_DIR}")
106
+ print(f"Test set: {len(test_data)} samples in {TEST_DIR}")
107
+
108
+ # Verify first entry format
109
+ print("\nSample entry format:")
110
+ print(json.dumps(train_data[0], indent=2))
111
+
test/0_18.jpg ADDED

Git LFS Details

  • SHA256: 8d1b5b46c30d2fa8a2111bf2538de4da526789c67ade32fc1ff9648f1ccac484
  • Pointer size: 130 Bytes
  • Size of remote file: 14.9 kB
test/0_9.jpg ADDED

Git LFS Details

  • SHA256: 42bb34e397b13482709ee0eca17e37fe6cdbd6f0e32f307e354da16efe518f27
  • Pointer size: 130 Bytes
  • Size of remote file: 61.7 kB
test/107_6.jpg ADDED

Git LFS Details

  • SHA256: 1f6279454f8aca0dd1df30fa97b8e16c6ee2b8ff2f98596d971e27485f57dec0
  • Pointer size: 130 Bytes
  • Size of remote file: 50.2 kB
test/118_1.jpg ADDED

Git LFS Details

  • SHA256: c8978862ae16dfc2cbaffc6be4f880a623fb8c176f8e42add4f7f9c7da872aa0
  • Pointer size: 130 Bytes
  • Size of remote file: 54.8 kB
test/120_17.jpg ADDED

Git LFS Details

  • SHA256: 60c1d3e394d607664af86fcb8f2c4d980fa02af1171ccdee87e7ff390e3cc328
  • Pointer size: 130 Bytes
  • Size of remote file: 22.6 kB
test/144_1.jpg ADDED

Git LFS Details

  • SHA256: ed88f790c7430cccb0177537eecf5d5a490fff87fced72ee9c56483b97fec9fa
  • Pointer size: 130 Bytes
  • Size of remote file: 20.9 kB
test/14_2.jpg ADDED

Git LFS Details

  • SHA256: 3a0ca77dccc73bef32bab394386d0a02296489e69ca8d15ee3878db37ce5a389
  • Pointer size: 130 Bytes
  • Size of remote file: 45 kB
test/153_13.jpg ADDED

Git LFS Details

  • SHA256: 5b24298a613153d5b0603f8a615478dff1bd8c06d1d2d33c44a0fe2f9b1205b0
  • Pointer size: 130 Bytes
  • Size of remote file: 56.3 kB
test/159_5.jpg ADDED

Git LFS Details

  • SHA256: b199806ce48c15ef0f84a449b2db02ee5c376a0a82ecfb65f100537609290337
  • Pointer size: 130 Bytes
  • Size of remote file: 31.1 kB
test/16_0.jpg ADDED

Git LFS Details

  • SHA256: 59d0f5d79e1a77eca37c4db279db787efc0958b505abb4b9ed66663bb3ceb1be
  • Pointer size: 130 Bytes
  • Size of remote file: 43 kB
test/184_0.jpg ADDED

Git LFS Details

  • SHA256: 6ee26d9a2863f428e24a137058c2b46a6c941dfe498b5325761c1d6e9fbf5068
  • Pointer size: 129 Bytes
  • Size of remote file: 5.46 kB
test/188_10.jpg ADDED

Git LFS Details

  • SHA256: b5e23086c2943391409b17e413d3d77f5c9cdd4edb667368f672e7bf8a802d5a
  • Pointer size: 130 Bytes
  • Size of remote file: 65.8 kB
test/195_8.jpg ADDED

Git LFS Details

  • SHA256: 7de59db30da12c268ea61605c733c58d5f0aaa1c16b96bb7b8223b5c7318db57
  • Pointer size: 130 Bytes
  • Size of remote file: 63.1 kB
test/215_15.jpg ADDED

Git LFS Details

  • SHA256: 57f9c7a9d79a95f289dd5b8470ff5413f663d4b7a601bfa018ddbb5784c34d1e
  • Pointer size: 130 Bytes
  • Size of remote file: 21.2 kB
test/217_11.jpg ADDED

Git LFS Details

  • SHA256: 29640447868203aaac1731fc988868fd3a181cbc7fe4f6944ab88a374817cc2b
  • Pointer size: 130 Bytes
  • Size of remote file: 36.8 kB
test/231_14.jpg ADDED

Git LFS Details

  • SHA256: 83d7dc6c40fcc1bf3b693735da252bf1eb69efbdcda0d76917c8b25d431b63ae
  • Pointer size: 130 Bytes
  • Size of remote file: 41.7 kB
test/235_8.jpg ADDED

Git LFS Details

  • SHA256: 56f891f926f4927cc9ae38b4807921e2557e399fb43c6a43f634556949aa22c7
  • Pointer size: 130 Bytes
  • Size of remote file: 32.1 kB
test/261_18.jpg ADDED

Git LFS Details

  • SHA256: 58c90f0cd1c5e9cfede16460a4f5c327e5aa3c0c359d8871fea4dc01927472ef
  • Pointer size: 129 Bytes
  • Size of remote file: 4.54 kB
test/270_9.jpg ADDED

Git LFS Details

  • SHA256: e63a6f90ce9b71da4d78e48b512985eadd2b3af0e45640dd36b4687807a74fff
  • Pointer size: 129 Bytes
  • Size of remote file: 6.25 kB
test/285_0.jpg ADDED

Git LFS Details

  • SHA256: b8546a68df2d72957328f8abaa885e324e702fe973b7867887e2f30df6c7b7dd
  • Pointer size: 130 Bytes
  • Size of remote file: 18 kB
test/287_13.jpg ADDED

Git LFS Details

  • SHA256: 77f87ac16136f1dcac919b4bc2077b6084ca992a7767a83dc2a15057c26e36ab
  • Pointer size: 130 Bytes
  • Size of remote file: 21.9 kB
test/295_12.jpg ADDED

Git LFS Details

  • SHA256: 8b2bcfc5d1688fecd7a416296996251ae27f4d311cc7bfbb501dc2571ad7e163
  • Pointer size: 130 Bytes
  • Size of remote file: 45.9 kB
test/302_6.jpg ADDED

Git LFS Details

  • SHA256: 99ee7f303e46942502469e6ea5d4fef69dfe117a28d34a92277ea1b1c74b3d15
  • Pointer size: 130 Bytes
  • Size of remote file: 20.5 kB
test/324_4.jpg ADDED

Git LFS Details

  • SHA256: df0b800c88c3a284067632efbf0c3ccefc9d6f71a76ff5d09fe1fff9f4ffe5b5
  • Pointer size: 130 Bytes
  • Size of remote file: 55.6 kB
test/361_18.jpg ADDED

Git LFS Details

  • SHA256: 2650dde9708d285c5b28bf5cbfbdbece663e318cda9b7461e8e363976a3748bf
  • Pointer size: 130 Bytes
  • Size of remote file: 37 kB
test/361_19.jpg ADDED

Git LFS Details

  • SHA256: 81331d9a3f87b79d83843b4a90dbe2c3da8a1a530eeba334f73832f9cbe33e21
  • Pointer size: 130 Bytes
  • Size of remote file: 39.7 kB
test/367_2.jpg ADDED

Git LFS Details

  • SHA256: af3282534571fdf6ed24b21d678022411f9bfc01e7477853ccab2b332e8f8f11
  • Pointer size: 130 Bytes
  • Size of remote file: 34 kB
test/378_4.jpg ADDED

Git LFS Details

  • SHA256: 437166f5fa2aeaa982211d9acafb939c6a8d3af5782c1dfd642c5b9461860403
  • Pointer size: 130 Bytes
  • Size of remote file: 12.7 kB
test/385_5.jpg ADDED

Git LFS Details

  • SHA256: 248daf978516fceaa06934e1bcd5d1bd67e55b69a2e6dfd03b599cf737ceea5c
  • Pointer size: 130 Bytes
  • Size of remote file: 14.8 kB
test/387_12.jpg ADDED

Git LFS Details

  • SHA256: dc4a95db66d6cbffd8885105b49f60733dd86f4faa5448cb5f36988722550ca7
  • Pointer size: 130 Bytes
  • Size of remote file: 33.6 kB
test/387_13.jpg ADDED

Git LFS Details

  • SHA256: 8640d1d060cf519f695b3d4d58916aba579a6bc566aa02cb86116bbbe4162eb6
  • Pointer size: 130 Bytes
  • Size of remote file: 17.6 kB
test/397_16.jpg ADDED

Git LFS Details

  • SHA256: 66019948adda3fe6227160969c7f315c48ee5370a71e80aae9bbbd9fe26a9a25
  • Pointer size: 130 Bytes
  • Size of remote file: 42.3 kB
test/401_11.jpg ADDED

Git LFS Details

  • SHA256: cda9d324a26722113e857f4cd2460cbd7dbd60c08d5e4957f0406bf96fb5d8d3
  • Pointer size: 129 Bytes
  • Size of remote file: 6.4 kB
test/413_10.jpg ADDED

Git LFS Details

  • SHA256: dc8f77ade2321a4261baacd83b32584219ca3ea3f9ffc15ac3a4382463795048
  • Pointer size: 130 Bytes
  • Size of remote file: 22.7 kB
test/414_0.jpg ADDED

Git LFS Details

  • SHA256: d829c5fd98cce62d64bb47f59ce0c4ebfd4bf1534f3ee2491211ed2c8c8718e1
  • Pointer size: 130 Bytes
  • Size of remote file: 25.5 kB
test/418_19.jpg ADDED

Git LFS Details

  • SHA256: f232df045ca4049439e6b8c5634a28288db9ca10ddbee8afa486c53963a8913d
  • Pointer size: 130 Bytes
  • Size of remote file: 39.6 kB
test/436_7.jpg ADDED

Git LFS Details

  • SHA256: 1e392489cf679fa31f33149019bec4b73f2f53ae4eb76d5e5fad2dea1dd5f809
  • Pointer size: 130 Bytes
  • Size of remote file: 55.5 kB
test/437_11.jpg ADDED

Git LFS Details

  • SHA256: 626ab2e87ce11638d62a3c0ea350e80e31ab65a292a174eadfb13788cca1cdc6
  • Pointer size: 130 Bytes
  • Size of remote file: 20.7 kB
test/440_8.jpg ADDED

Git LFS Details

  • SHA256: b7207ecdbda9d70bc9509ca387557066f659a6941cb6d7464dc39173961f06c0
  • Pointer size: 130 Bytes
  • Size of remote file: 39.4 kB
test/455_5.jpg ADDED

Git LFS Details

  • SHA256: 6d1cabfa94f5d2747a15d3f099422188c932c9962bd380f9a15a0ba8a00a9b1f
  • Pointer size: 129 Bytes
  • Size of remote file: 9.11 kB
test/45_16.jpg ADDED

Git LFS Details

  • SHA256: 8550a5c5007361e500ceecaadf15ff23341b57afcbca8097986c0462897cb02e
  • Pointer size: 130 Bytes
  • Size of remote file: 64.2 kB
test/477_3.jpg ADDED

Git LFS Details

  • SHA256: e943885e8ee0072ceeaed6007422db53642254a7f3eddcc202274cba0e1e158c
  • Pointer size: 130 Bytes
  • Size of remote file: 57.7 kB
test/493_3.jpg ADDED

Git LFS Details

  • SHA256: a99000aad3a7fb83e3231f04e9fbe339fbaff99f0cbefaf332ef60825d8a7123
  • Pointer size: 130 Bytes
  • Size of remote file: 23 kB
test/499_9.jpg ADDED

Git LFS Details

  • SHA256: f067acb002aa765908723fdd22d3e37ed22d60fa01e21433c54c65d60fbbf7fe
  • Pointer size: 130 Bytes
  • Size of remote file: 36.4 kB
test/59_13.jpg ADDED

Git LFS Details

  • SHA256: fbeb008ce1609858043a144077e77d234618d256220964656bf06b5c9f1971d5
  • Pointer size: 130 Bytes
  • Size of remote file: 33.2 kB
test/97_18.jpg ADDED

Git LFS Details

  • SHA256: 244c2080c66c36c08a0e100093f4003ba3455bcda3b0edf97a5479b6b874ce6c
  • Pointer size: 130 Bytes
  • Size of remote file: 36.6 kB
test/metadata.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
train/metadata.jsonl ADDED
The diff for this file is too large to render. See raw diff