garythung commited on
Commit
94cd17e
1 Parent(s): 8568674

Add dataset

Browse files
Files changed (5) hide show
  1. README.txt +1 -0
  2. constants.py +9 -0
  3. dataset-original.zip +3 -0
  4. dataset-resized.zip +3 -0
  5. resize.py +66 -0
README.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ The datasets have been zipped for simplicity. If using this dataset, please give a citation of the repository at github.com/garythung/trashnet. Please refer to the repository for more details about the files.
constants.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ GLASS = 0
2
+ PAPER = 1
3
+ CARDBOARD = 2
4
+ PLASTIC = 3
5
+ METAL = 4
6
+ TRASH = 5
7
+
8
+ DIM1 = 384
9
+ DIM2 = 512
dataset-original.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e46374d6da507b3ac5934a0e7769c21235d9ed0e2329da72ca847f866e5f706
3
+ size 3634187193
dataset-resized.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c060e8abfe5d6de0578ca15be1ed8ad0794a865d333c3473d53d1d9ad6e38b8c
3
+ size 42834870
resize.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import constants
3
+ import numpy as np
4
+ from scipy import misc, ndimage
5
+
6
+ def resize(image, dim1, dim2):
7
+ return misc.imresize(image, (dim1, dim2))
8
+
9
+ def fileWalk(directory, destPath):
10
+ try:
11
+ os.makedirs(destPath)
12
+ except OSError:
13
+ if not os.path.isdir(destPath):
14
+ raise
15
+
16
+ for subdir, dirs, files in os.walk(directory):
17
+ for file in files:
18
+ if len(file) <= 4 or file[-4:] != '.jpg':
19
+ continue
20
+
21
+ pic = misc.imread(os.path.join(subdir, file))
22
+ dim1 = len(pic)
23
+ dim2 = len(pic[0])
24
+ if dim1 > dim2:
25
+ pic = np.rot90(pic)
26
+
27
+ picResized = resize(pic,constants.DIM1, constants.DIM2)
28
+ misc.imsave(os.path.join(destPath, file), picResized)
29
+
30
+
31
+ def main():
32
+ prepath = os.path.join(os.getcwd(), 'dataset-original')
33
+ glassDir = os.path.join(prepath, 'glass')
34
+ paperDir = os.path.join(prepath, 'paper')
35
+ cardboardDir = os.path.join(prepath, 'cardboard')
36
+ plasticDir = os.path.join(prepath, 'plastic')
37
+ metalDir = os.path.join(prepath, 'metal')
38
+ trashDir = os.path.join(prepath, 'trash')
39
+
40
+ destPath = os.path.join(os.getcwd(), 'dataset-resized')
41
+ try:
42
+ os.makedirs(destPath)
43
+ except OSError:
44
+ if not os.path.isdir(destPath):
45
+ raise
46
+
47
+ #GLASS
48
+ fileWalk(glassDir, os.path.join(destPath, 'glass'))
49
+
50
+ #PAPER
51
+ fileWalk(paperDir, os.path.join(destPath, 'paper'))
52
+
53
+ #CARDBOARD
54
+ fileWalk(cardboardDir, os.path.join(destPath, 'cardboard'))
55
+
56
+ #PLASTIC
57
+ fileWalk(plasticDir, os.path.join(destPath, 'plastic'))
58
+
59
+ #METAL
60
+ fileWalk(metalDir, os.path.join(destPath, 'metal'))
61
+
62
+ #TRASH
63
+ fileWalk(trashDir, os.path.join(destPath, 'trash'))
64
+
65
+ if __name__ == '__main__':
66
+ main()