def predict(fname_specialists='net2.pickle'): with open(fname_specialists, 'rb') as f: net = pickle.load(f) X = load2d(test=True)[0] y_pred = net.predict(X) y_pred2 = y_pred * 48 + 48 y_pred2 = y_pred2.clip(0, 96) df = DataFrame(y_pred2) lookup_table = read_csv(os.path.expanduser(FLOOKUP)) values = [] for index, row in lookup_table.iterrows(): values.append(( row.RowId, y_pred2[int(row.ImageId)-1][int(row.RowId)%30-1] )) submission = DataFrame(values, columns=('RowId','Location')) filename = 'submission1.csv' submission.to_csv(filename, index=False) print("Wrote {}".format(filename))
#('conv3', layers.Conv2DLayer), #('pool3', layers.MaxPool2DLayer), ('hidden4', layers.DenseLayer), # ('hidden5', layers.DenseLayer), ('output', layers.DenseLayer), ], input_shape=(None, 1, 96, 96), conv1_num_filters=32, conv1_filter_size=(3, 3), pool1_pool_size=(2, 2), conv2_num_filters=64, conv2_filter_size=(2, 2), pool2_pool_size=(2, 2), #conv3_num_filters=128, conv3_filter_size=(2, 2), pool3_pool_size=(2, 2), hidden4_num_units=500, #hidden5_num_units=500, output_num_units=30, output_nonlinearity=None, update_learning_rate=0.01, update_momentum=0.9, regression=True, max_epochs=30, verbose=1, ) X, y = load2d() # load 2-d data net2.fit(X, y) with open('net2.pickle', 'wb') as f: pickle.dump(net2, f, -1)
FLOOKUP = 'IdLookupTable.csv' def plot_sample(x, y, axis,y_true=None): img = x.reshape(96, 96) axis.imshow(img, cmap='gray') axis.scatter(y[0::2] * 48 + 48, y[1::2] * 48 + 48, c='b',marker='x', s=10) if y_true !=None: axis.scatter(y_true[0::2] * 48 + 48, y_true[1::2] * 48 + 48,c='r', marker='x', s=10) f1 = open('net1.pickle', 'r') f2 = open('net2.pickle', 'r') net1 = pickle.load(f1) net2 = pickle.load(f2) X1,y1 = load() X2,y2 = load2d() #X2 = load2d(test=True) sample1,y_true1 = X1[6:7],y1[6] sample2,y_true2 = X2[6:7],y2[6] y_pred1 = net1.predict(sample1)[0] y_pred2 = net2.predict(sample2)[0] fig = plt.figure(figsize=(6, 3)) ax = fig.add_subplot(1, 2, 1, xticks=[], yticks=[]) plot_sample(sample1[0], y_pred1, ax,y_true1) ax = fig.add_subplot(1, 2, 2, xticks=[], yticks=[])