Esempio n. 1
0
def main(argv):
	file = open(argv[0], 'r')
	net = pickle.load(file)
	print 'Loaded net'

	isVal = len(argv) > 1 and argv[1] == 'val'
	print 'isVal: ', isVal

	X, y_gt = load2d(isVal=isVal, isTiny=False)
	print 'Loaded data'
	y_pred = net.predict(X)
	print 'Predicted data'

	pdj = getPDJ(y_gt, y_pred)
	fig = pyplot.figure(figsize=(6, 6))
	axes = pyplot.gca()
	pyplot.grid()
	axes.set_ylim([0.0, 1.0])
	axes.set_xlim([0.0, 0.5])
	pyplot.xlabel('Normalized distance to true joint')
	pyplot.ylabel('Detection rate')
	pyplot.title('PDJ for different limbs over various thresholds')
	
	fractions = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5] 
	pyplot.plot(fractions, pdj[:,0], linewidth=2, label='head', color='#FC474C') 
	pyplot.plot(fractions, pdj[:,1], linewidth=2, label='torso', color='#8DE047')
	pyplot.plot(fractions, pdj[:,2], linewidth=2, label='arms', color='#FFDD50')
	pyplot.plot(fractions, pdj[:,3], linewidth=2, label='legs', color='#53A3D7')

	pyplot.legend(loc='upper left', shadow=True, fontsize='medium')

	pyplot.savefig('detections')	
def main(argv):
	file = open(argv[0], 'r')
	net = pickle.load(file)

	print 'Loaded net'

	isTest = len(argv) > 1 and argv[1] == 'test'
	print 'isTest: ', isTest

	X, _ = load2d(test=isTest, isTiny=False)
	print 'Loaded data'
	print 'X shape: ', X.shape
	y_pred = net.predict(X)
	print "y_pred shape: ", y_pred.shape
	print "x shape: ", X.shape

	print 'Predicted data'

	fig = pyplot.figure(figsize=(6, 6))
	fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)

	for i in range(42):
		ax = fig.add_subplot(6, 7, i + 1, xticks=[], yticks=[])
		plot_sample(X[i], y_pred[i], ax)
	pyplot.savefig('segments')
Esempio n. 3
0
def submission(fname_net="net4.pickle"):
    with open(fname_net, "rb") as f:
        net = pickle.load(f)  # net = specialists

    X = load.load2d(test=True)[0]
    y_pred = net.predict(X)
    print "Finish predict test file"
    columns = "left_eye_center_x,left_eye_center_y,right_eye_center_x,right_eye_center_y,left_eye_inner_corner_x,left_eye_inner_corner_y,left_eye_outer_corner_x,left_eye_outer_corner_y,right_eye_inner_corner_x,right_eye_inner_corner_y,right_eye_outer_corner_x,right_eye_outer_corner_y,left_eyebrow_inner_end_x,left_eyebrow_inner_end_y,left_eyebrow_outer_end_x,left_eyebrow_outer_end_y,right_eyebrow_inner_end_x,right_eyebrow_inner_end_y,right_eyebrow_outer_end_x,right_eyebrow_outer_end_y,nose_tip_x,nose_tip_y,mouth_left_corner_x,mouth_left_corner_y,mouth_right_corner_x,mouth_right_corner_y,mouth_center_top_lip_x,mouth_center_top_lip_y,mouth_center_bottom_lip_x,mouth_center_bottom_lip_y"
    columns = columns.split(",")

    y_pred = y_pred * 48 + 48
    y_pred = y_pred.clip(0, 96)
    df = DataFrame(y_pred, columns=columns)

    lookup_table = read_csv(os.path.expanduser("./data/IdLookupTable.csv"))
    values = []

    for index, row in lookup_table.iterrows():
        values.append((row["RowId"], df.ix[row.ImageId - 1][row.FeatureName]))

    now_str = datetime.now().isoformat().replace(":", "-")
    submission = DataFrame(values, columns=("RowId", "Location"))
    filename = "submission-{}.csv".format(now_str)
    submission.to_csv(filename, index=False)
    print ("Wrote {}".format(filename))
def main(argv):
    file = open(argv[0], "r")
    net = pickle.load(file)
    print "Loaded net"

    isVal = len(argv) > 1 and argv[1] == "val"
    print "isVal: ", isVal

    X, y_gt = load2d(isVal=isVal, isTiny=False)
    print "Loaded data"
    y_pred = net.predict(X)
    print "Predicted data"

    pdj = getPDJ(y_gt, y_pred)
    fig = pyplot.figure(figsize=(6, 6))
    axes = pyplot.gca()
    pyplot.grid()
    axes.set_ylim([0.0, 1.0])
    axes.set_xlim([0.0, 0.5])
    pyplot.xlabel("Normalized distance to true joint")
    pyplot.ylabel("Detection rate")
    pyplot.title("PDJ for different limbs over various thresholds")

    fractions = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
    pyplot.plot(fractions, pdj[:, 0], linewidth=2, label="head", color="#FC474C")
    pyplot.plot(fractions, pdj[:, 1], linewidth=2, label="torso", color="#8DE047")
    pyplot.plot(fractions, pdj[:, 2], linewidth=2, label="arms", color="#FFDD50")
    pyplot.plot(fractions, pdj[:, 3], linewidth=2, label="legs", color="#53A3D7")

    pyplot.legend(loc="upper left", shadow=True, fontsize="medium")

    pyplot.savefig("detections")
Esempio n. 5
0
def submission(fname_net='net4.pickle'):
    with open(fname_net, 'rb') as f:
        net = pickle.load(f)  # net = specialists

    X = load.load2d(test=True)[0]
    y_pred = net.predict(X)
    print 'Finish predict test file'
    columns = 'left_eye_center_x,left_eye_center_y,right_eye_center_x,right_eye_center_y,left_eye_inner_corner_x,left_eye_inner_corner_y,left_eye_outer_corner_x,left_eye_outer_corner_y,right_eye_inner_corner_x,right_eye_inner_corner_y,right_eye_outer_corner_x,right_eye_outer_corner_y,left_eyebrow_inner_end_x,left_eyebrow_inner_end_y,left_eyebrow_outer_end_x,left_eyebrow_outer_end_y,right_eyebrow_inner_end_x,right_eyebrow_inner_end_y,right_eyebrow_outer_end_x,right_eyebrow_outer_end_y,nose_tip_x,nose_tip_y,mouth_left_corner_x,mouth_left_corner_y,mouth_right_corner_x,mouth_right_corner_y,mouth_center_top_lip_x,mouth_center_top_lip_y,mouth_center_bottom_lip_x,mouth_center_bottom_lip_y'
    columns = columns.split(',')

    y_pred = y_pred * 48 + 48
    y_pred = y_pred.clip(0, 96)
    df = DataFrame(y_pred, columns=columns)

    lookup_table = read_csv(os.path.expanduser('./data/IdLookupTable.csv'))
    values = []

    for index, row in lookup_table.iterrows():
        values.append((
            row['RowId'],
            df.ix[row.ImageId - 1][row.FeatureName],
        ))

    now_str = datetime.now().isoformat().replace(':', '-')
    submission = DataFrame(values, columns=('RowId', 'Location'))
    filename = 'submission-{}.csv'.format(now_str)
    submission.to_csv(filename, index=False)
    print("Wrote {}".format(filename))
def main(argv):
    file = open(argv[0], 'r')
    net = pickle.load(file)

    print 'Loaded net'

    isTest = len(argv) > 1 and argv[1] == 'test'
    print 'isTest: ', isTest

    X, _ = load2d(test=isTest, isTiny=False)
    print 'Loaded data'
    print 'X shape: ', X.shape
    y_pred = net.predict(X)
    print "y_pred shape: ", y_pred.shape
    print "x shape: ", X.shape

    print 'Predicted data'

    fig = pyplot.figure(figsize=(6, 6))
    fig.subplots_adjust(left=0,
                        right=1,
                        bottom=0,
                        top=1,
                        hspace=0.05,
                        wspace=0.05)

    for i in range(42):
        ax = fig.add_subplot(6, 7, i + 1, xticks=[], yticks=[])
        plot_sample(X[i], y_pred[i], ax)
    pyplot.savefig('segments')
def main(argv):
    file = open(argv[0], 'r')
    net = pickle.load(file)

    print 'Loaded net'

    isTest = len(argv) > 1 and argv[1] == 'test'
    print 'isTest: ', isTest

    X, _ = load2d(test=isTest, isTiny=False)
    print 'Loaded data'
    y_pred = net.predict(X)
    print "y_pred shape: ", y_pred.shape
    print "X shape: ", X.shape

    print 'Predicted data'

    for i in range(y_pred.shape[0]):
        print i
        fig = pyplot.figure(figsize=(6, 6))
        fig.subplots_adjust(left=0,
                            right=1,
                            bottom=0,
                            top=1,
                            hspace=0.05,
                            wspace=0.05)
        plot_sample(X[i], y_pred[i])
        pyplot.savefig('segments/' + str(i))
        pyplot.close(fig)
Esempio n. 8
0
def main(argv):
    file = open(argv[0], 'r')
    fraction = float(argv[1])
    net = pickle.load(file)

    isVal = (len(argv) > 2) and (argv[2] == 'val')

    X, y_gt = load2d(isVal=isVal)  # for training
    y_pred = net.predict(X)

    # 0-based indices for torso
    shoulder_l = 9
    hip_r = 2

    num_examples = y_gt.shape[0]
    num_joint_coords = y_gt.shape[1]
    pdj = [0] * 14

    # Iterates over each example
    for i in xrange(num_examples):
        num_correct_joints = 0
        y_gt_tup = []
        y_pred_tup = []

        # Builds tuple vector of joints (x, y)
        for j in xrange(0, num_joint_coords, 2):
            y_gt_tup.append((y_gt[i, j], y_gt[i, j + 1]))
            y_pred_tup.append((y_pred[i, j], y_pred[i, j + 1]))

        torso_diameter = tup_distance(y_gt_tup[shoulder_l], y_gt_tup[hip_r])
        error_radius = fraction * torso_diameter

        # Iterates over each joint
        for j in xrange(len(y_gt_tup)):
            if withinThreshold(y_gt_tup[j], y_pred_tup[j], error_radius):
                pdj[j] += 1

    print "num examples: ", num_examples
    pdj = [x / float(num_examples) for x in pdj]
    print "PDJ: ", pdj
    overall = sum(pdj) / len(pdj)
    print "PDJ: ", overall

    head = (pdj[12] + pdj[13]) / 2
    torso = (pdj[12] + pdj[3] + pdj[2] + pdj[8] + pdj[9]) / 5
    arms = (pdj[11] + pdj[10] + pdj[9] + pdj[8] + pdj[7] + pdj[6]) / 6
    legs = (pdj[5] + pdj[4] + pdj[3] + pdj[2] + pdj[1] + pdj[0]) / 6
    print "PDJ head, torso, arms, legs: ", [head, torso, arms, legs]
def main(argv):
	file = open(argv[0], 'r')
	net = pickle.load(file)

	isTest = len(argv) > 1 and argv[1] == 'test'

	X, _ = load2d(test=isTest)
	y_pred = net.predict(X)

	fig = pyplot.figure(figsize=(6, 6))
	fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)

	for i in range(16):
		ax = fig.add_subplot(4, 4, i + 1, xticks=[], yticks=[])
		plot_sample(X[i], y_pred[i], ax)
	pyplot.savefig('samples')
Esempio n. 10
0
def main(argv):
    file = open(argv[0], 'r')
    net = pickle.load(file)

    isVal = (len(argv) > 2) and (argv[2] == 'val')

    X, y_gt = load2d(isVal=isVal)  # for training
    print "y_gt shape: ", y_gt.shape
    y_pred = net.predict(X)

    total_limbs = 14  # 2x ankle-knee, 2x knee-hip, hip-hip, 2x hip-shoulder, neck-head, 2x shoulder-neck, 2x shoulder-elbow, 2x elbow-wrist
    pair_indices = [(5, 4), (0, 1), (3, 4), (1, 2), (2, 3), (9, 3), (8, 2),
                    (10, 11), (9, 10), (9, 12), (12, 8), (7, 8), (6, 7),
                    (12, 13)]

    #pair_indices = [(0, 1), (1, 2), (4, 5), (3, 4), (6, 7), (7, 8), (10, 11), (9, 10), (12, 13)]
    #pair_indices = [(9, 12), (8, 12), (9, 3), (2, 3), (2, 8)] # torso

    pcp = [0] * len(pair_indices)
    num_examples = y_gt.shape[0]
    num_joints = y_gt.shape[1]

    # Iterates over each example
    for i in xrange(num_examples):
        y_gt_tup = []
        y_pred_tup = []

        # Builds tuple vector of joints (x, y)
        for j in xrange(0, num_joints, 2):
            y_gt_tup.append((y_gt[i, j], y_gt[i, j + 1]))
            y_pred_tup.append((y_pred[i, j], y_pred[i, j + 1]))

        # Iterates over each joint pairing
        #for a,b in pair_indices:
        for x in range(len(pair_indices)):
            a, b = pair_indices[x]
            gt_distance = tup_distance(y_gt_tup[a], y_gt_tup[b])
            error_radius = 0.5 * gt_distance

            if withinThreshold(y_pred_tup[a], y_gt_tup[a],
                               error_radius) or withinThreshold(
                                   y_pred_tup[b], y_gt_tup[b], error_radius):
                pcp[x] += 1

    pcp = [x / float(num_examples) for x in pcp]
    print "PCP: ", pcp
Esempio n. 11
0
def main(argv):
	file = open(argv[0], 'r')
	net = pickle.load(file)

	isVal = (len(argv) > 2) and (argv[2] == 'val')

	X, y_gt = load2d(isVal=isVal) # for training
	print "y_gt shape: ", y_gt.shape
	y_pred = net.predict(X)

	total_limbs = 14 # 2x ankle-knee, 2x knee-hip, hip-hip, 2x hip-shoulder, neck-head, 2x shoulder-neck, 2x shoulder-elbow, 2x elbow-wrist
	pair_indices = [(5, 4), (0, 1), (3, 4), (1, 2), (2, 3), (9, 3), (8, 2), (10, 11), (9, 10), (9, 12), (12, 8), (7, 8), (6, 7), (12, 13)]

	#pair_indices = [(0, 1), (1, 2), (4, 5), (3, 4), (6, 7), (7, 8), (10, 11), (9, 10), (12, 13)]
	#pair_indices = [(9, 12), (8, 12), (9, 3), (2, 3), (2, 8)] # torso 

	pcp = [0] * len(pair_indices)
	num_examples = y_gt.shape[0]
	num_joints = y_gt.shape[1] 
	
	# Iterates over each example
	for i in xrange(num_examples):
		y_gt_tup = []
		y_pred_tup = []

		# Builds tuple vector of joints (x, y)
		for j in xrange(0, num_joints, 2):
			y_gt_tup.append((y_gt[i, j], y_gt[i, j+1]))
			y_pred_tup.append((y_pred[i, j], y_pred[i, j+1]))

		# Iterates over each joint pairing
		#for a,b in pair_indices:
		for x in range(len(pair_indices)):
			a, b = pair_indices[x]
			gt_distance = tup_distance(y_gt_tup[a], y_gt_tup[b])
			error_radius = 0.5 * gt_distance

			if withinThreshold(y_pred_tup[a], y_gt_tup[a], error_radius) or withinThreshold(y_pred_tup[b], y_gt_tup[b], error_radius):
				pcp[x] += 1

	pcp = [x / float(num_examples) for x in pcp]
	print "PCP: ", pcp
def main(argv):
    file = open(argv[0], 'r')
    net = pickle.load(file)

    isTest = len(argv) > 1 and argv[1] == 'test'

    X, _ = load2d(test=isTest)
    y_pred = net.predict(X)

    fig = pyplot.figure(figsize=(6, 6))
    fig.subplots_adjust(left=0,
                        right=1,
                        bottom=0,
                        top=1,
                        hspace=0.05,
                        wspace=0.05)

    for i in range(16):
        ax = fig.add_subplot(4, 4, i + 1, xticks=[], yticks=[])
        plot_sample(X[i], y_pred[i], ax)
    pyplot.savefig('samples')
Esempio n. 13
0
def main():
    csv.field_size_limit(sys.maxsize)
    sys.setrecursionlimit(10000)
    X, y = load2d()  # load 2-d data

    print "Loaded data"

    #net_pretrain = None
    #with open('kfkd-net3.pickle', 'rb') as f:
    #	net_pretrain = pickle.load(f)

    #from sklearn.base import clone
    #net3 = clone(net_pretrain)
    #set number of epochs relative to number of training examples:
    #net3.max_epochs = int(1e7 / y.shape[0])

    net3.fit(X, y)

    with open('net3.pickle', 'wb') as f:
        pickle.dump(net3, f, -1)

    print "MSE: ", mean_squared_error(net3.predict(X), y)
Esempio n. 14
0
def main():
	csv.field_size_limit(sys.maxsize)
	sys.setrecursionlimit(10000)
	X, y = load2d()  # load 2-d data

	print "Loaded data"

	#net_pretrain = None
	#with open('kfkd-net3.pickle', 'rb') as f:
	#	net_pretrain = pickle.load(f)

	#from sklearn.base import clone
	#net3 = clone(net_pretrain)
	#set number of epochs relative to number of training examples:
	#net3.max_epochs = int(1e7 / y.shape[0])

	net3.fit(X, y)

	with open('net3.pickle', 'wb') as f:
		pickle.dump(net3, f, -1)

	print "MSE: ", mean_squared_error(net3.predict(X), y)	
def main(argv):
	file = open(argv[0], 'r')
	net = pickle.load(file)

	print 'Loaded net'

	isTest = len(argv) > 1 and argv[1] == 'test'
	print 'isTest: ', isTest

	X, _ = load2d(test=isTest, isTiny=False)
	print 'Loaded data'
	y_pred = net.predict(X)
	print "y_pred shape: ", y_pred.shape
	print "X shape: ", X.shape

	print 'Predicted data'

	for i in range(y_pred.shape[0]):
		print i
		fig = pyplot.figure(figsize=(6, 6))
		fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
		plot_sample(X[i], y_pred[i])
		pyplot.savefig('segments/' + str(i))
		pyplot.close(fig)
Esempio n. 16
0
import cPickle as pickle
with open('SpeM2.pickle', 'wb') as f4:
    pickle.dump(net_spe_M, f4, -1)


########################################################
#  load the full net and the specialists sequentially  #
########################################################


# ------ make full image prediction first ----------- #

with open('net4.pickle', 'rb') as f0:
     net_full = pickle.load(f0)

X = load.load2d(test=True)[0]
print X.shape
y_pred = net_full.predict(X)
y_pred_final1 = np.zeros(y_pred.shape)         # array to save the final predictions of each specialists
y_pred_final2 = np.zeros(y_pred.shape)

# ------ load the trained nets together to make the final predict ---------- #

# LE
# with open('SpeLE.pickle', 'rb') as f2:
#      net_spe_LE = pickle.load(f2)

X_LE_test, x_co_LE, y_co_LE = load.load_spe_test(win=win, X_test=X, Y_pred=y_pred, indices=indices_LE)
y_LE_pred = net_spe_LE.predict(X_LE_test)
y_LE_pred_big = np.zeros(y_LE_pred.shape)
num_r = y_LE_pred.shape[0]
Esempio n. 17
0
    update_momentum=theano.shared(float32(0.9)),
    regression=True,
    batch_iterator_train=FlipBatchIterator2d(batch_size=128),
    on_epoch_finished=[
        AdjustVariable('update_learning_rate', start=0.03, stop=0.0001),
        AdjustVariable('update_momentum', start=0.9, stop=0.999),
    ],
    max_epochs=3000,
    verbose=1,
)

import sys

sys.setrecursionlimit(10000)

X, y = load.load2d()  # load 2-d data
net4.fit(X, y)

# Training for 1000 epochs will take a while.  We'll pickle the
# trained model so that we can load it back later:
import cPickle as pickle
with open('net4.pickle', 'wb') as f:
    pickle.dump(net4, f, -1)

# make submission
print 'start making submission'


def submission(fname_net='net4.pickle'):
    with open(fname_net, 'rb') as f:
        net = pickle.load(f)  # net = specialists
Esempio n. 18
0
    update_momentum=theano.shared(float32(0.9)),
    regression=True,
    batch_iterator_train=FlipBatchIterator2d(batch_size=128),
    on_epoch_finished=[
        AdjustVariable("update_learning_rate", start=0.03, stop=0.0001),
        AdjustVariable("update_momentum", start=0.9, stop=0.999),
    ],
    max_epochs=3000,
    verbose=1,
)

import sys

sys.setrecursionlimit(10000)

X, y = load.load2d()  # load 2-d data
net4.fit(X, y)

# Training for 1000 epochs will take a while.  We'll pickle the
# trained model so that we can load it back later:
import cPickle as pickle

with open("net4.pickle", "wb") as f:
    pickle.dump(net4, f, -1)

# make submission
print "start making submission"


def submission(fname_net="net4.pickle"):
    with open(fname_net, "rb") as f:
Esempio n. 19
0
def MSE(argv):
	file = open(argv[0], 'r')
	net = pickle.load(file)

	X, y = load2d()  # load 2-d data
	print "MSE: ", mean_squared_error(net.predict(X), y)
Esempio n. 20
0
net_spe_M.fit(X_M, Y_M)
# pickle the trained specialists
import cPickle as pickle
with open('SpeM2.pickle', 'wb') as f4:
    pickle.dump(net_spe_M, f4, -1)

########################################################
#  load the full net and the specialists sequentially  #
########################################################

# ------ make full image prediction first ----------- #

with open('net4.pickle', 'rb') as f0:
    net_full = pickle.load(f0)

X = load.load2d(test=True)[0]
print X.shape
y_pred = net_full.predict(X)
y_pred_final1 = np.zeros(
    y_pred.shape)  # array to save the final predictions of each specialists
y_pred_final2 = np.zeros(y_pred.shape)

# ------ load the trained nets together to make the final predict ---------- #

# LE
# with open('SpeLE.pickle', 'rb') as f2:
#      net_spe_LE = pickle.load(f2)

X_LE_test, x_co_LE, y_co_LE = load.load_spe_test(win=win,
                                                 X_test=X,
                                                 Y_pred=y_pred,
Esempio n. 21
0
def MSE(argv):
	file = open(argv[0], 'r')
	net = pickle.load(file)

	X, y = load2d(isVal=True)  # load 2-d data
	print "MSE: ", mean_squared_error(net.predict(X), y)