vkashko commited on
Commit
250cd79
1 Parent(s): 38952e9

refactor: remove useless

Browse files
Files changed (1) hide show
  1. facial_keypoint_detection.py +0 -94
facial_keypoint_detection.py CHANGED
@@ -1,8 +1,5 @@
1
  import datasets
2
- import numpy as np
3
  import pandas as pd
4
- import PIL.Image
5
- import PIL.ImageOps
6
 
7
  _CITATION = """\
8
  @InProceedings{huggingface:dataset,
@@ -27,66 +24,6 @@ _LICENSE = "cc-by-nc-nd-4.0"
27
  _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
28
 
29
 
30
- def exif_transpose(img):
31
- if not img:
32
- return img
33
-
34
- exif_orientation_tag = 274
35
-
36
- # Check for EXIF data (only present on some files)
37
- if hasattr(img, "_getexif") and isinstance(
38
- img._getexif(), dict) and exif_orientation_tag in img._getexif():
39
- exif_data = img._getexif()
40
- orientation = exif_data[exif_orientation_tag]
41
-
42
- # Handle EXIF Orientation
43
- if orientation == 1:
44
- # Normal image - nothing to do!
45
- pass
46
- elif orientation == 2:
47
- # Mirrored left to right
48
- img = img.transpose(PIL.Image.FLIP_LEFT_RIGHT)
49
- elif orientation == 3:
50
- # Rotated 180 degrees
51
- img = img.rotate(180)
52
- elif orientation == 4:
53
- # Mirrored top to bottom
54
- img = img.rotate(180).transpose(PIL.Image.FLIP_LEFT_RIGHT)
55
- elif orientation == 5:
56
- # Mirrored along top-left diagonal
57
- img = img.rotate(-90,
58
- expand=True).transpose(PIL.Image.FLIP_LEFT_RIGHT)
59
- elif orientation == 6:
60
- # Rotated 90 degrees
61
- img = img.rotate(-90, expand=True)
62
- elif orientation == 7:
63
- # Mirrored along top-right diagonal
64
- img = img.rotate(90,
65
- expand=True).transpose(PIL.Image.FLIP_LEFT_RIGHT)
66
- elif orientation == 8:
67
- # Rotated 270 degrees
68
- img = img.rotate(90, expand=True)
69
-
70
- return img
71
-
72
-
73
- def load_image_file(file, mode='RGB'):
74
- # Load the image with PIL
75
- img = PIL.Image.open(file)
76
-
77
- if hasattr(PIL.ImageOps, 'exif_transpose'):
78
- # Very recent versions of PIL can do exit transpose internally
79
- img = PIL.ImageOps.exif_transpose(img)
80
- else:
81
- # Otherwise, do the exif transpose ourselves
82
- img = exif_transpose(img)
83
-
84
- img = img.convert(mode)
85
- img.thumbnail((1000, 1000), PIL.Image.Resampling.LANCZOS)
86
-
87
- return img
88
-
89
-
90
  class FacialKeypointDetection(datasets.GeneratorBasedBuilder):
91
 
92
  def _info(self):
@@ -103,13 +40,9 @@ class FacialKeypointDetection(datasets.GeneratorBasedBuilder):
103
  license=_LICENSE)
104
 
105
  def _split_generators(self, dl_manager):
106
- # images = dl_manager.download_and_extract(f"{_DATA}images.zip")
107
- # masks = dl_manager.download_and_extract(f"{_DATA}masks.zip")
108
  images = dl_manager.download(f"{_DATA}images.tar.gz")
109
  masks = dl_manager.download(f"{_DATA}masks.tar.gz")
110
  annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
111
- # images = dl_manager.iter_files(images)
112
- # masks = dl_manager.iter_files(masks)
113
  images = dl_manager.iter_archive(images)
114
  masks = dl_manager.iter_archive(masks)
115
 
@@ -138,30 +71,3 @@ class FacialKeypointDetection(datasets.GeneratorBasedBuilder):
138
  },
139
  'key_points': annotations_df['key_points'].iloc[idx]
140
  }
141
- # images_data = pd.DataFrame(
142
- # columns=['image_name', 'image_path', 'mask_path'])
143
- # for idx, ((image_path, image),
144
- # (mask_path, mask)) in enumerate(zip(images, masks)):
145
- # images_data.loc[idx] = {
146
- # 'image_name': image_path.split('/')[-1],
147
- # 'image_path': image_path,
148
- # 'mask_path': mask_path
149
- # }
150
-
151
- # annotations_df = pd.merge(annotations_df,
152
- # images_data,
153
- # how='left',
154
- # on=['image_name'])
155
-
156
- # annotations_df[['image_path', 'mask_path'
157
- # ]] = annotations_df[['image_path',
158
- # 'mask_path']].astype('string')
159
-
160
- # for row in annotations_df.sort_values(['image_name'
161
- # ]).itertuples(index=False):
162
- # yield idx, {
163
- # 'image_id': row[0],
164
- # 'image': row[3],
165
- # 'mask': row[4],
166
- # 'key_points': row[2]
167
- # }
 
1
  import datasets
 
2
  import pandas as pd
 
 
3
 
4
  _CITATION = """\
5
  @InProceedings{huggingface:dataset,
 
24
  _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
25
 
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  class FacialKeypointDetection(datasets.GeneratorBasedBuilder):
28
 
29
  def _info(self):
 
40
  license=_LICENSE)
41
 
42
  def _split_generators(self, dl_manager):
 
 
43
  images = dl_manager.download(f"{_DATA}images.tar.gz")
44
  masks = dl_manager.download(f"{_DATA}masks.tar.gz")
45
  annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
 
 
46
  images = dl_manager.iter_archive(images)
47
  masks = dl_manager.iter_archive(masks)
48
 
 
71
  },
72
  'key_points': annotations_df['key_points'].iloc[idx]
73
  }