nateraw commited on
Commit
ddad27b
1 Parent(s): 9927112

Create rock_paper_scissors.py

Browse files
Files changed (1) hide show
  1. rock_paper_scissors.py +74 -0
rock_paper_scissors.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The TensorFlow Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Rock, Paper, Scissors dataset."""
17
+ import re
18
+ from pathlib import Path
19
+
20
+ import datasets
21
+
22
+ _CITATION = """\
23
+ @ONLINE {rps,
24
+ author = "Laurence Moroney",
25
+ title = "Rock, Paper, Scissors Dataset",
26
+ month = "feb",
27
+ year = "2019",
28
+ url = "http://laurencemoroney.com/rock-paper-scissors-dataset"
29
+ }
30
+ """
31
+
32
+ _URLS = {
33
+ 'train': "https://storage.googleapis.com/download.tensorflow.org/data/rps.zip",
34
+ 'test': "https://storage.googleapis.com/download.tensorflow.org/data/rps-test-set.zip"
35
+ }
36
+ _NAMES = ["rock", "paper", "scissors"]
37
+
38
+ class RockPaperScissors(datasets.GeneratorBasedBuilder):
39
+ """Rock, Paper, Scissors dataset."""
40
+
41
+ def _info(self):
42
+ return datasets.DatasetInfo(
43
+ description="Images of hands playing rock, paper, scissor game.",
44
+ features=datasets.Features({
45
+ "file":
46
+ datasets.Value("string"),
47
+ "labels":
48
+ datasets.features.ClassLabel(names=sorted(tuple(_NAMES))),
49
+ }),
50
+ supervised_keys=("file", "labels"),
51
+ homepage="http://laurencemoroney.com/rock-paper-scissors-dataset",
52
+ citation=_CITATION
53
+ )
54
+
55
+ def _split_generators(self, dl_manager):
56
+ data_files = dl_manager.download_and_extract(_URLS)
57
+ return [
58
+ datasets.SplitGenerator(
59
+ name=datasets.Split.TRAIN,
60
+ gen_kwargs={
61
+ "archive": data_files['train'],
62
+ }),
63
+ datasets.SplitGenerator(
64
+ name=datasets.Split.TEST,
65
+ gen_kwargs={
66
+ "archive": data_files['test'],
67
+ }),
68
+ ]
69
+
70
+ def _generate_examples(self, archive):
71
+ labels = self.info.features['labels']
72
+ for i, path in enumerate(Path(archive).glob('**/*')):
73
+ if path.suffix == '.png':
74
+ yield i, dict(file=path.as_posix(), labels=labels.encode_example(path.parent.name.lower()))