def __init__(self, weightsname, *unused, **unused_kw): self._net = df.Sequential( # 48x70 (HxW) df.SpatialConvolution(3, 24, (3, 3)), # 46x68 df.BatchNormalization(24), df.ReLU(), df.SpatialConvolution(24, 24, (3, 3)), # 44x66 df.BatchNormalization(24), df.SpatialMaxPooling((2, 3)), # 22x22 df.ReLU(), df.SpatialConvolution(24, 48, (3, 3)), # 20x20 df.BatchNormalization(48), df.ReLU(), df.SpatialConvolution(48, 48, (3, 3)), # 18x18 df.BatchNormalization(48), df.SpatialMaxPooling((2, 2)), # 9x9 df.ReLU(), df.SpatialConvolution(48, 64, (3, 3)), # 7x7 df.BatchNormalization(64), df.ReLU(), df.SpatialConvolution(64, 64, (3, 3)), # 5x5 df.BatchNormalization(64), df.ReLU(), df.Dropout(0.2), Flatten(), df.Linear(64 * 5 * 5, 512), df.ReLU(), df.Dropout(0.5), df.Linear(512, 2, init=df.init.normal(0.01)), Biternion()) self._net.__setstate__(np.load(weightsname)) self._net.evaluate() self._aug = AugmentationPipeline(None, None, Cropper((48, 70)))
def mkaug(Xtr, ytr): return AugmentationPipeline( Xtr, ytr, Cropper((48, 70)), # Gamma(), )
def main(): X, y, n = pickle.load(gzip.open('data/TownCentre.pkl.gz', 'rb')) (Xtr, ytr, ntr), (Xte, yte, nte) = split_dataset(X, y, n, split=0.9) Xtr, ytr = Xtr.astype(df.floatX) / 255, ytr.astype(df.floatX) Xte, yte = Xte.astype(df.floatX) / 255, yte.astype(df.floatX) aug = AugmentationPipeline(Xtr, ytr, Cropper((46, 46))) print("Trainset: {}".format(len(Xtr))) print("Testset: {}".format(len(Xte))) # Naive deep regression # net = mknet_gpu(df.Linear(512, 1, initW=df.init.const(0))) # dotrain(net, df.MADCriterion(), aug, Xtr, ytr[:, None]) # dostats(net, aug, Xtr, batchsize=1000) # y_preds = np.squeeze(dopred_deg(net, aug, Xte)) # Biternion deep regression with cosine criterion # net = mknet_gpu(df.Linear(512, 2, initW=df.init.normal(0.01)), Biternion()) # dotrain(net, CosineCriterion(), aug, Xtr, deg2bit(ytr)) # dostats(net, aug, Xtr, batchsize=1000) # y_preds = bit2deg(np.squeeze(dopred_deg(net, aug, Xte))) # Biternion deep regression with Von-Mises criterion net = mknet_gpu(df.Linear(512, 2, initW=df.init.normal(0.01)), Biternion()) dotrain(net, VonMisesBiternionCriterion(1), aug, Xtr, deg2bit(ytr)) dostats(net, aug, Xtr, batchsize=1000) y_preds = bit2deg(np.squeeze(dopred_deg(net, aug, Xte))) loss = maad_from_deg(y_preds, yte) mean_loss = np.mean(loss) std_loss = np.std(loss) print("MAAD error (test) : %f ± %f" % (mean_loss, std_loss)) return
def __init__(self, weightsname, *unused, **unused_kw): self._net = df.Sequential( # 3@46 df.SpatialConvolution( 3, 24, (3, 3)), # -> 24@44 df.BatchNormalization(24), df.ReLU(), df.SpatialConvolution(24, 24, (3, 3)), # -> 24@42 df.BatchNormalization(24), df.SpatialMaxPooling((2, 2), ignore_border=False), # -> 24@21 df.ReLU(), df.SpatialConvolution(24, 48, (3, 3)), # -> 48@19 df.BatchNormalization(48), df.ReLU(), df.SpatialConvolution(48, 48, (3, 3)), # -> 48@17 df.BatchNormalization(48), df.SpatialMaxPooling((2, 2), ignore_border=False), # -> 48@9 df.ReLU(), df.SpatialConvolution(48, 64, (3, 3)), # -> 64@7 df.BatchNormalization(64), df.ReLU(), df.SpatialConvolution(64, 64, (3, 3)), # -> 64@5 df.BatchNormalization(64), df.ReLU(), df.Dropout(0.2), Flatten(), df.Linear(64*5*5, 512), df.ReLU(), df.Dropout(0.5), df.Linear(512, 2, init=df.init.normal(0.01)), Biternion() ) self._net.__setstate__(np.load(weightsname)) self._net.evaluate() self._aug = AugmentationPipeline(None, None, Cropper((46, 46)))
def __init__(self, weightsname, *unused, **unused_kw): self._net = df.Sequential( # 184x76 df.SpatialConvolution(3, 24, (3, 3)), # 182x74 df.BatchNormalization(24), df.ReLU(), df.SpatialConvolution(24, 24, (3, 3)), # 180x72 df.SpatialMaxPooling((3, 3)), # 60x24 df.BatchNormalization(24), df.ReLU(), df.SpatialConvolution(24, 48, (3, 3)), # 58x22 df.BatchNormalization(48), df.ReLU(), df.SpatialConvolution(48, 48, (3, 3)), # 56x20 df.SpatialMaxPooling((2, 2)), # 28x10 df.BatchNormalization(48), df.ReLU(), df.SpatialConvolution(48, 64, (3, 3)), # 26x8 df.BatchNormalization(64), df.ReLU(), df.SpatialConvolution(64, 64, (3, 3)), # 24x6 df.SpatialMaxPooling((2, 2)), # 12x3 df.BatchNormalization(64), df.ReLU(), df.SpatialConvolution(64, 64, (3, 2)), # 10x2 df.BatchNormalization(64), df.ReLU(), df.Dropout(0.2), Flatten(), df.Linear(64 * 10 * 2, 512), df.ReLU(), df.Dropout(0.5), df.Linear(512, 2, init=df.init.normal(0.01)), Biternion()) self._net.__setstate__(np.load(weightsname)) self._net.evaluate() self._aug = AugmentationPipeline(None, None, Cropper((184, 76)))
def mkaug(Xtr, ytr): return AugmentationPipeline(Xtr, ytr, Cropper((184, 76)))
data, label, Number = pickle.load(gzip.open('data/TownCentre.pkl.gz', 'rb')) # Train,TestData (trainX, trainY, trainNum), (testX, testY, testNum) = split(data, label, Number, split=0.9) #trainX,trainY = trainX.astype(df.floatX)/255,trainY.astype(df.floatX) trainX, trainY = trainX.astype(np.float32) / 255, trainY.astype(np.float32) #testX,testY = testX.astype(df.floatX)/255,testY.astype(df.floatX) testX, testY = testX.astype(np.float32) / 255, testY.astype(np.float32) pdb.set_trace() ################### Pure Linear Regression ####################### aug = AugmentationPipeline(trainX, trainY, Cropper((46, 46))) #LinearTrain = [dotrain(net,df.MADCriterion(),aug,trainX,trainY[:,None]) for net in nets_shallow_linreg] nets_shallow_linreg = [ df.Sequential(Flatten(), df.Linear(3 * 46 * 46, 1, init=df.init.const(0))) for _ in range(10) ] LinearPred = [ Flatten().dopred_deg(net, aug, testX) for net in nets_shallow_linreg ] Flatten().Error(LinearPred, testY[:, None]) pdb.set_trace() #################### Deep Linear Regression ##################