本文整理汇总了Python中util.Util.get_files方法的典型用法代码示例。如果您正苦于以下问题:Python Util.get_files方法的具体用法?Python Util.get_files怎么用?Python Util.get_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Util
的用法示例。
在下文中一共展示了Util.get_files方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: frames2batch
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import get_files [as 别名]
def frames2batch(k = 12,batch_size = 1024, is_calib = False):
pos = util.get_files(rootdir = 'F:\\train_data\\pos\\')
neg = util.get_files(rootdir = 'F:\\train_data\\neg\\')
pos = shuffle(pos)
neg = shuffle(neg)
total = pos + neg
total = shuffle(total)
batch = []
c = 0
bpath = 'F:\\train_data\\batch\\'
for item_path in total:
frame = fr.get_frame(item_path)
frame_r = fr.resize_frame(frame,(k,k))
if frame_r == None:
continue
vec = fr.frame_to_vect(frame_r)
label = 1 if item_path.split('\\')[-1].find('pos') > 0 else 0
print(item_path,label)
batch.append((vec,label))
if len(batch) > 0 and len(batch) % batch_size == 0:
batch = sp.array(batch)
sp.savez(bpath + str(c) + '_' + str(k) + ('_' if not is_calib else '_calib-') + 'net',batch)
batch = []
c += 1
if len(batch) > 0 and len(batch) % batch_size == 0:
batch = sp.array(batch)
sp.savez(bpath + str(c) + '_' + str(k) + ('_' if not is_calib else '_calib') + '-net',batch)
batch = []
c += 1
示例2: train_on_hdd
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import get_files [as 别名]
def train_on_hdd(self,rootdir = '12-net/'):
print(self.nn_name,'training start...','data folder',rootdir)
mean_acc = 0
total_time = 0
bpaths = util.get_files(rootdir = rootdir,fexpr = '*.npz')
m = len(bpaths)
r = len(util.load_from_npz(bpaths [-1]))
total_len = m * len(util.load_from_npz(bpaths [0]))
print('data input size is around',total_len)
for epoch in range(self.max_epochs):
self.eta.set_value(self.l_rates[epoch])
t_loss = 0
start = time()
for bpath in bpaths:
batch = util.load_from_npz(bpath)
items,labels = batch[:,0],batch[:,1]
items = sp.array([e.astype(sp.float32) for e in items])
labels = labels.astype(sp.int32)
X_train, X_val, y_train, y_val = train_test_split(items,labels,test_size = 0.25)
t_loss += self.__train_fn__ (X_train,y_train)
val_acc = 0
val_batches = 0
for xval,yval in self.iterate_minibatches(X_val,y_val,16):
err, acc = self.__val_fn__(xval, yval)
val_acc += acc
val_batches += 1
if self.verbose:
dur = time() - start
a0 = 100*(val_acc/val_batches)
mean_acc += a0
total_time += dur
print("epoch %d out of %d \t loss %g \t acсuracy %g \t time %d s \t" % (epoch + 1,self.max_epochs, t_loss / (total_len),a0,dur))
m = (total_time)//60
s = total_time - 60 * m
h = m//60
m = m - 60 * h
mean_acc = mean_acc / self.max_epochs
print('Training end with total time %d h %d m %d s and mean accouracy over epochs %g' % (h,m,s,mean_acc))