当前位置: 首页>>代码示例>>Python>>正文


Python Util.load_from_npz方法代码示例

本文整理汇总了Python中util.Util.load_from_npz方法的典型用法代码示例。如果您正苦于以下问题:Python Util.load_from_npz方法的具体用法?Python Util.load_from_npz怎么用?Python Util.load_from_npz使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在util.Util的用法示例。


在下文中一共展示了Util.load_from_npz方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: train

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import load_from_npz [as 别名]
def train(nn_name = '12-net',rootdir = 'F:\\'):
    """
    Fucntion for traning 12-net with testing on part of data
    using cross validation
    """
    is_calib = nn_name.find('calib') > 0
    
    X_name = 'train_data_'+('icalib_' if is_calib else '' )+ nn_name[:2] + '.npz'
    y_name = 'labels_'+('icalib_' if is_calib else '' )+ nn_name[:2] + '.npz'
    is_calib = nn_name.find('calib') > 0
    rates = sp.hstack((0.05 * sp.ones(333,dtype=sp.float32),0.005*sp.ones(333,dtype=sp.float32),0.0005*sp.ones(333,dtype=sp.float32),
                         0.00005*sp.ones(5,dtype=sp.float32)))
    rates12 = rates
    rates24 = rates
    rates48 = rates
    rates12_c =  rates12[333:666]
    rates48_c = rates12_c
    rates24_c = rates12_c
    if nn_name == '24-net':
        if is_calib:
            nn = Cnnl(nn_name = nn_name,l_rates=rates24_c)
        else:
            nn = Cnnl(nn_name = nn_name,l_rates=rates24)
    elif nn_name == '48-net':    
        if is_calib:
            nn = Cnnl(nn_name = nn_name,l_rates=rates48_c)
        else:
            nn = Cnnl(nn_name = nn_name,l_rates=rates48)
    else:
        if is_calib:
            nn = Cnnl(nn_name = nn_name,l_rates=rates12_c)
        else:
            nn = Cnnl(nn_name = nn_name,l_rates = rates12)
    
    if is_calib:
        X = util.load_from_npz(X_name)
        y = util.load_from_npz(y_name)
        nn.fit(X,y)
    else:
        rpath = os.path.join(rootdir,'traindata',nn.nn_name)
        nn.train_on_hdd(rootdir = rpath)
    nn.__save_model_old__(nn_name   + '_lasagne_.pickle')
开发者ID:gogolgrind,项目名称:Cascade-CNN-Face-Detection,代码行数:44,代码来源:train.py

示例2: train_on_hdd

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import load_from_npz [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))
开发者ID:gogolgrind,项目名称:Cascade-CNN-Face-Detection,代码行数:43,代码来源:cnn_cascade_lasagne.py

示例3: cv

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import load_from_npz [as 别名]
	def cv(nn_name,d_num = 10000,k_fold = 7,score_metrics = 'accuracy',verbose = 0):
		suff = str(nn_name[:2])
		if nn_name.find('calib') > 0:
			X_data_name = 'train_data_icalib_'+ suff +  '.npz'
			y_data_name = 'labels_icalib_'+ suff + '.npz'
		else:
			X_data_name = 'train_data_'+ suff +  '.npz'
			y_data_name = 'labels_'+ suff + '.npz'
		X,y = util.load_from_npz(X_data_name),util.load_from_npz(y_data_name)
		d_num = min(len(X),d_num)        
		X = X[:d_num]
		y = y[:d_num] 
		rates12 = sp.hstack((0.001 * sp.ones(70,dtype=sp.float32),0.0001*sp.ones(20,dtype=sp.float32),0.00001*sp.ones(5,dtype=sp.float32)))
		rates24 = sp.hstack((0.01 * sp.ones(25,dtype=sp.float32),0.0001*sp.ones(15,dtype=sp.float32)))
		rates48 = sp.hstack ([0.05 * sp.ones(15,dtype=sp.float32),0.005*sp.ones(10,dtype=sp.float32) ])
		if nn_name == '48-net':
			X12 = util.load_from_npz('train_data_12.npz')[:d_num]
			X24 = util.load_from_npz('train_data_24.npz')[:d_num]
		elif nn_name == '24-net':
			X12 = util.load_from_npz('train_data_12.npz')[:d_num]
			
		if score_metrics == 'accuracy':
			score_fn = accuracy_score
		elif score_metrics == 'f1':
			score_fn = f1_score
		elif score_metrics == 'recall':
			score_fn = recall_score
			
		scores = []
		iteration = 0
		for t_indx,v_indx in util.kfold(X,y,k_fold=k_fold):
			nn = None
			X_train,X_test,y_train,y_test = X[t_indx], X[v_indx], y[t_indx], y[v_indx]
			
			#print('\t \t',str(iteration+1),'fold out of ',str(k_fold),'\t \t' )
			if nn_name == '24-net':
				nn = Cnnl(nn_name = nn_name,l_rates=rates24,verbose=verbose,subnet=Cnnl(nn_name = '12-net',l_rates=rates12,verbose=verbose).load_model(
				'12-net_lasagne_.pickle'))
				nn.fit(X = X_train,y = y_train,X12 = X12[t_indx])
			elif nn_name == '48-net':
				nn = Cnnl(nn_name = nn_name,l_rates=rates48,subnet=Cnnl(nn_name = '24-net',l_rates=rates24,subnet=Cnnl(nn_name = '12-net',l_rates=rates12).load_model(
				'12-net_lasagne_.pickle')).load_model('24-net_lasagne_.pickle'))
				nn.fit(X = X_train,y = y_train,X12 = X12[t_indx],X24 = X24[t_indx])
			else:
				
				nn = Cnnl(nn_name = nn_name,l_rates=rates12,verbose=0)
				nn.fit(X = X_train,y = y_train)
		
			if nn_name == '24-net':  
				y_pred = nn.predict(X_test,X12=X12[v_indx])
			elif nn_name == '48-net':
				y_pred = nn.predict(X_test,X12=X12[v_indx],X24=X24[v_indx])
			else:
				y_pred = nn.predict(X_test)
			score = score_fn(y_test,y_pred)
			
			#print(iteration,'fold score',score)
			scores.append(score)
			iteration += 1
		score_mean = sp.array(scores).mean()
		print(d_num,'mean score',score)
		return score_mean
开发者ID:gogolgrind,项目名称:Cascade-CNN-Face-Detection,代码行数:64,代码来源:cv.py


注:本文中的util.Util.load_from_npz方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。