Zaid commited on
Commit
9122911
·
verified ·
1 Parent(s): 7253d5b

Upload NewDataset.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. NewDataset.py +5 -5
NewDataset.py CHANGED
@@ -6,7 +6,7 @@ import zipfile
6
 
7
  class NewDataset(datasets.GeneratorBasedBuilder):
8
  def _info(self):
9
- return datasets.DatasetInfo(features=datasets.Features({'path':datasets.Value('string'),'image':datasets.Image(),'label': datasets.features.ClassLabel(names=['cat', 'dog\n'])}))
10
 
11
  def extract_all(self, dir):
12
  zip_files = glob(dir+'/**/**.zip', recursive=True)
@@ -30,7 +30,7 @@ class NewDataset(datasets.GeneratorBasedBuilder):
30
 
31
  def read_image(self, filepath):
32
  if filepath.endswith('.jpg') or filepath.endswith('.png'):
33
- raw_data = {'filepath':[filepath], 'bytes':[filepath]}
34
  else:
35
  raw_data = {'text':[open(filepath).read()]}
36
  return pd.DataFrame(raw_data)
@@ -42,10 +42,10 @@ class NewDataset(datasets.GeneratorBasedBuilder):
42
  dfs = [df]
43
  dfs.append(self.read_image(filepaths['targets1'][i]))
44
  df = pd.concat(dfs, axis = 1)
45
- if len(df.columns) != 3:
46
  continue
47
- df.columns = ['path', 'image', 'text']
48
  for _, record in df.iterrows():
49
- yield str(_id), {'path':record['path'],'image':record['image'],'label':str(record['text'])}
50
  _id += 1
51
 
 
6
 
7
  class NewDataset(datasets.GeneratorBasedBuilder):
8
  def _info(self):
9
+ return datasets.DatasetInfo(features=datasets.Features({'image':datasets.Image(),'text':datasets.Value('string')}))
10
 
11
  def extract_all(self, dir):
12
  zip_files = glob(dir+'/**/**.zip', recursive=True)
 
30
 
31
  def read_image(self, filepath):
32
  if filepath.endswith('.jpg') or filepath.endswith('.png'):
33
+ raw_data = {'bytes':[filepath]}
34
  else:
35
  raw_data = {'text':[open(filepath).read()]}
36
  return pd.DataFrame(raw_data)
 
42
  dfs = [df]
43
  dfs.append(self.read_image(filepaths['targets1'][i]))
44
  df = pd.concat(dfs, axis = 1)
45
+ if len(df.columns) != 2:
46
  continue
47
+ df.columns = ['image', 'text']
48
  for _, record in df.iterrows():
49
+ yield str(_id), {'image':record['image'],'text':record['text']}
50
  _id += 1
51