jalFaizy commited on
Commit
0d87e08
1 Parent(s): a16f9bf

remove bugs

Browse files
.gitignore CHANGED
@@ -117,4 +117,5 @@ dmypy.json
117
  trial.ipynb
118
 
119
  # original data
120
- original_data/
 
 
117
  trial.ipynb
118
 
119
  # original data
120
+ original_data/
121
+ cache_dir/
data/train.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2c0717779d3b83d32ed81bfcdd91468ad9a00135978fde76ed1f4cdb02010ba3
3
- size 1254072
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56e72010436361979b537553f53e1387240c297532c78361fbb3d5cdf95df935
3
+ size 1248852
data/valid.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:438cad2398de0ba6af7f69c208459a65967d45272edd42186cf1bfcf2ecf13be
3
- size 321278
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9fcbd463bfab4fbdf11c894d1d9002425fdb1f77dd8d8c4d38fbd39569401eea
3
+ size 319706
dataset_infos.json CHANGED
@@ -1 +1 @@
1
- {"jalFaizy--detect_chess_pieces": {"description": "", "citation": "", "homepage": "", "license": "", "features": {"image": {"decode": true, "id": null, "_type": "Image"}, "label": {"num_classes": 4, "names": ["blackKing", "whiteKing", "blackQueen", "whiteQueen"], "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": [{"task": "object-detection", "image_column": "image", "label_column": "label"}], "builder_name": "imagefolder", "config_name": "default", "version": {"version_str": "0.0.0", "description": null, "major": 0, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1257869.0, "num_examples": 204, "dataset_name": "detect_chess_pieces"}, "validation": {"name": "validation", "num_bytes": 320797.0, "num_examples": 52, "dataset_name": "detect_chess_pieces"}}, "download_checksums": null, "download_size": 316483, "post_processing_size": null, "dataset_size": 1578666.0, "size_in_bytes": 1895149.0}}
 
1
+ {"jalFaizy--detect_chess_pieces": {"description": "", "citation": "", "homepage": "", "license": "", "features": {"image": {"decode": true, "id": null, "_type": "Image"}, "label": {"num_classes": 4, "names": ["blackKing", "whiteKing", "blackQueen", "whiteQueen"], "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "imagefolder", "config_name": "default", "version": {"version_str": "0.0.0", "description": null, "major": 0, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1257869.0, "num_examples": 204, "dataset_name": "detect_chess_pieces"}, "validation": {"name": "validation", "num_bytes": 320797.0, "num_examples": 52, "dataset_name": "detect_chess_pieces"}}, "download_checksums": null, "download_size": 316483, "post_processing_size": null, "dataset_size": 1578666.0, "size_in_bytes": 1895149.0}, "default": {"description": "The \"Object Detection for Chess Pieces\" dataset is a toy dataset created (as suggested by the name!) to introduce object detection in a beginner friendly way.\n", "citation": "", "homepage": "https://github.com/faizankshaikh/chessDetection", "license": "CC-BY-SA:2.0", "features": {"image": {"decode": true, "id": null, "_type": "Image"}, "objects": {"feature": {"label": {"num_classes": 4, "names": ["blackKing", "whiteKing", "blackQueen", "whiteQueen"], "id": null, "_type": "ClassLabel"}, "bbox": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": 4, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "detect_chess_pieces", "config_name": "default", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 32768, "num_examples": 204, "dataset_name": "detect_chess_pieces"}, "validation": {"name": "validation", "num_bytes": 8353, "num_examples": 52, "dataset_name": "detect_chess_pieces"}}, "download_checksums": {"data/train.zip": {"num_bytes": 1248852, "checksum": "56e72010436361979b537553f53e1387240c297532c78361fbb3d5cdf95df935"}, "data/valid.zip": {"num_bytes": 319706, "checksum": "9fcbd463bfab4fbdf11c894d1d9002425fdb1f77dd8d8c4d38fbd39569401eea"}}, "download_size": 1568558, "post_processing_size": null, "dataset_size": 41121, "size_in_bytes": 1609679}}
detect_chess_pieces.py CHANGED
@@ -15,9 +15,11 @@
15
 
16
 
17
  import os
18
-
19
  import datasets
20
 
 
 
 
21
  _CITATION = ""
22
 
23
  _DESCRIPTION = """\
@@ -28,9 +30,11 @@ _HOMEPAGE = "https://github.com/faizankshaikh/chessDetection"
28
 
29
  _LICENSE = "CC-BY-SA:2.0"
30
 
31
- _REPO = "data" # "https://huggingface.co/datasets/jalFaizy/resolve/main/data"
32
  _URLS = {"train": f"{_REPO}/train.zip", "valid": f"{_REPO}/valid.zip"}
33
 
 
 
34
 
35
  class DetectChessPieces(datasets.GeneratorBasedBuilder):
36
  """Object Detection for Chess Pieces dataset"""
@@ -42,7 +46,10 @@ class DetectChessPieces(datasets.GeneratorBasedBuilder):
42
  features=datasets.Features(
43
  {
44
  "image": datasets.Image(),
45
- "bboxes": datasets.Sequence(datasets.Value("int32"), length=5),
 
 
 
46
  }
47
  ),
48
  supervised_keys=None,
@@ -54,6 +61,7 @@ class DetectChessPieces(datasets.GeneratorBasedBuilder):
54
 
55
  def _split_generators(self, dl_manager):
56
  data_dir = dl_manager.download_and_extract(_URLS)
 
57
  return [
58
  datasets.SplitGenerator(
59
  name=datasets.Split.TRAIN,
@@ -68,14 +76,18 @@ class DetectChessPieces(datasets.GeneratorBasedBuilder):
68
  def _generate_examples(self, split, data_dir):
69
  image_dir = os.path.join(data_dir, "images")
70
  label_dir = os.path.join(data_dir, "labels")
71
- for idx, (image_path, label_path) in enumerate(zip(image_dir, label_dir)):
 
 
 
 
72
  im = Image.open(image_path)
73
  width, height = im.size
74
 
75
  with open(label_path, "r") as f:
76
  lines = f.readlines()
77
 
78
- bboxes = []
79
  for line in lines:
80
  line = line.strip().split()
81
  try:
@@ -87,7 +99,10 @@ class DetectChessPieces(datasets.GeneratorBasedBuilder):
87
  except:
88
  print(f"Check file {f.name} for errors")
89
 
90
- bbox = [bbox_class, bbox_xcenter, bbox_ycenter, bbox_width, bbox_height]
91
- bboxes.append(bbox)
 
 
 
92
 
93
- yield idx, {"image": image_path, "bboxes": bboxes}
 
15
 
16
 
17
  import os
 
18
  import datasets
19
 
20
+ from PIL import Image
21
+ from glob import glob
22
+
23
  _CITATION = ""
24
 
25
  _DESCRIPTION = """\
 
30
 
31
  _LICENSE = "CC-BY-SA:2.0"
32
 
33
+ _REPO = "data"# "https://huggingface.co/datasets/jalFaizy/detect_chess_pieces/raw/main/data"
34
  _URLS = {"train": f"{_REPO}/train.zip", "valid": f"{_REPO}/valid.zip"}
35
 
36
+ _CATEGORIES = ["blackKing", "whiteKing", "blackQueen", "whiteQueen"]
37
+
38
 
39
  class DetectChessPieces(datasets.GeneratorBasedBuilder):
40
  """Object Detection for Chess Pieces dataset"""
 
46
  features=datasets.Features(
47
  {
48
  "image": datasets.Image(),
49
+ "objects": datasets.Sequence({
50
+ "label": datasets.ClassLabel(names=_CATEGORIES),
51
+ "bbox": datasets.Sequence(datasets.Value("int32"), length=4)
52
+ }),
53
  }
54
  ),
55
  supervised_keys=None,
 
61
 
62
  def _split_generators(self, dl_manager):
63
  data_dir = dl_manager.download_and_extract(_URLS)
64
+ print(data_dir["train"])
65
  return [
66
  datasets.SplitGenerator(
67
  name=datasets.Split.TRAIN,
 
76
  def _generate_examples(self, split, data_dir):
77
  image_dir = os.path.join(data_dir, "images")
78
  label_dir = os.path.join(data_dir, "labels")
79
+
80
+ image_paths = sorted(glob(image_dir + "/*/*.png"))
81
+ label_paths = sorted(glob(label_dir + "/*/*.txt"))
82
+
83
+ for idx, (image_path, label_path) in enumerate(zip(image_paths, label_paths)):
84
  im = Image.open(image_path)
85
  width, height = im.size
86
 
87
  with open(label_path, "r") as f:
88
  lines = f.readlines()
89
 
90
+ objects = []
91
  for line in lines:
92
  line = line.strip().split()
93
  try:
 
99
  except:
100
  print(f"Check file {f.name} for errors")
101
 
102
+ #bbox = [bbox_class, bbox_xcenter, bbox_ycenter, bbox_width, bbox_height]
103
+ objects.append({
104
+ "label": bbox_class,
105
+ "bbox": [bbox_xcenter, bbox_ycenter, bbox_width, bbox_height]
106
+ })
107
 
108
+ yield idx, {"image": image_path, "objects": objects}