示例#1
0
 def module1(params, train_images):
     time_start = time.time()
     ph = Pixelhop2(TH1=0.0001,
                    TH2=0.0001,
                    SaabArgs=params.SaabArgs,
                    neighborArgs=params.neighborArgs,
                    poolingArg=params.poolingArg)
     ph.fit(train_images)
     print("Time cost - PixelHop++ units:", time.time() - time_start)
     del train_images
     # save data to files
     save_data(ph, os.path.join(params.save_data, "ph"))
示例#2
0
    'win': 5,
    'stride': 1
}, {
    'func': ShrinkAvg,
    'win': 5,
    'stride': 1
}, {
    'func': ShrinkAvg,
    'win': 5,
    'stride': 1
}]
concatArg = {'func': Concat}

p2_avg = Pixelhop2(depth=3,
                   TH1=0.001,
                   TH2=0.0001,
                   SaabArgs=SaabArgs,
                   shrinkArgs=shrinkArgs,
                   concatArg=concatArg)
p2_avg.fit(x_train)
# output_train_avg = p2_avg.transform(x_train)

# SaabArgs = [{'num_AC_kernels':-1, 'needBias':False, 'useDC':True, 'batch':None, 'cw':False},
#             {'num_AC_kernels':-1, 'needBias':True, 'useDC':True, 'batch':None, 'cw':True},
#             {'num_AC_kernels':-1, 'needBias':True, 'useDC':True, 'batch':None, 'cw':True}]
# shrinkArgs = [{'func':ShrinkMax, 'win':7, 'stride':1},
#              {'func': ShrinkMax, 'win':5, 'stride':1},
#              {'func': ShrinkMax, 'win':3, 'stride':1}]
# concatArg = {'func':Concat}
#
# p2_max = Pixelhop2(depth=3, TH1=0.001, TH2=0.0001, SaabArgs=SaabArgs, shrinkArgs=shrinkArgs, concatArg=concatArg)
# p2_max.fit(x_train)
f.close()
f = open('Train12500.pckl', 'rb')
XTrain12500, YTrain12500 = pickle.load(f)
f.close()

# In[ ]:

#Train module 1 with window size of 3x3
#train pixelHop++ Units
##Module 1
##train 1st unit(depth 1), 2nd unit(depth 2), 3rd unit(depth 3) at once
#constructor arguments are provided in homework instruction
depthOfSSL = 3
pixelHop2Obj = Pixelhop2(depth=depthOfSSL,
                         TH1=0.001,
                         TH2=0.0001,
                         SaabArgs=SaabArgs,
                         shrinkArgs=shrinkArgs,
                         concatArg=concatArg)

#training module 1 at all depths
timerObj.tic()  #Elapsed time is 246.831189 seconds.
pixelHop2Obj.fit(XTrain6250)
print('Time for training module 1 at all depths: ')
timerObj.toc()

#Save pixelHop2 model
fileName_PixelHop2_6250_3x3 = 'pixelHop2_Cla_6250_3x3.sav'
pickle.dump(pixelHop2Obj, open(fileName_PixelHop2_6250_3x3, 'wb'))

# In[ ]:
示例#4
0
    'stride': 1,
    'num': 5
}]
concatArg = {'func': Concat}

# Training Process

# In[5]:

#Training Time Starts
trainStart = datetime.datetime.now()
#PixelHop Fitting
print("Training the Module 1 of PixelHop")
model = Pixelhop2(depth=5,
                  TH1=0.0012,
                  TH2=0.00012,
                  SaabArgs=SaabArgs,
                  shrinkArgs=shrinkArgs,
                  concatArg=concatArg)
model.fit(fitData)
#Using Batching Method To Do the Transform
print("Extracting Features of Training Data")
features_train_raw = PH_Transform(megaSize, batchSize, trainDataSet, model)
#Merge Training Image Features
features_train_layer1, features_train_layer2, features_train_layer3, features_train_layer4, features_train_layer5 = merge_Features(
    features_train_raw, megaSize)
#Feature Selection Process
print("Selecting Features of Training Data")
#Calculate the Cross Entrophy for Each Channel
CE1, CE2, CE3, CE4, CE5 = cal_CE(features_train_layer1, features_train_layer2,
                                 features_train_layer3, features_train_layer4,
                                 features_train_layer5, trainLabelSet)