@@ -124,7 +124,10 @@ def dropPadding(idx, padding):
124
124
print ('Frames before: {}. Frames after: {}' .format (len (idx ), len (res )))
125
125
return res
126
126
127
- def processFolder (folder , timeDelta , testRatio , framesPerChunk , testPadding , skippedFrames ):
127
+ def processFolder (
128
+ folder , timeDelta , testRatio , framesPerChunk , testPadding , skippedFrames ,
129
+ minFrames
130
+ ):
128
131
print ('Processing' , folder )
129
132
dataset = loadNpz (folder )
130
133
for k , v in dataset .items ():
@@ -164,6 +167,11 @@ def saveSubset(filename, idx):
164
167
for fn in files :
165
168
os .remove (os .path .join (folder , fn ))
166
169
print ('Removed' , len (files ), 'files' )
170
+
171
+ totalFrames = len (testing ) + len (training )
172
+ if minFrames < totalFrames :
173
+ print ('Not enough frames: %d < %d' % (totalFrames , minFrames ))
174
+ return 0 , 0
167
175
# save training and testing sets
168
176
saveSubset ('train.npz' , training )
169
177
saveSubset ('test.npz' , testing )
@@ -199,7 +207,8 @@ def main(args):
199
207
testFramesN , trainFramesN = processFolder (
200
208
path ,
201
209
args .time_delta , args .test_ratio , args .frames_per_chunk ,
202
- args .test_padding , args .skipped_frames
210
+ args .test_padding , args .skipped_frames ,
211
+ minFrames = args .min_frames
203
212
)
204
213
testFrames += testFramesN
205
214
trainFrames += trainFramesN
@@ -233,6 +242,11 @@ def main(args):
233
242
'--skipped-frames' , type = str , default = 'train' , choices = ['train' , 'test' , 'drop' ],
234
243
help = 'What to do with skipped frames ("train", "test", or "drop")'
235
244
)
245
+ parser .add_argument (
246
+ '--min-frames' , type = int , default = 0 ,
247
+ help = 'Minimum number of frames in a chunk'
248
+ )
249
+
236
250
args = parser .parse_args ()
237
251
main (args )
238
252
pass
0 commit comments