def testcase2(): np.random.seed(2) data = tf.placeholder(name = 'data', shape = (None, None, None, 1), dtype=tf.float32) rois = tf.placeholder(name = 'rois', shape = (None, 5), dtype = tf.float32 ) [y, argmax] = roi_pooling_op.roi_pool(data, rois, 6, 6, 1.0) init = tf.initialize_all_variables() sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init) for step in xrange(1): img = np.zeros( (100 ,100) ) for i in range(100): for j in range(100): img[i][j] = ( i/10 ) * 10 + j/10; #this is a block matirx composed of 10x10 blocks from 0 .. 100 randomInput = np.tile( np.expand_dims(img, 2), (32, 1, 1, 1) ) res = sess.run( y, feed_dict = { data : randomInput, rois : [[0, 10, 10, 15, 15], [31, 30, 30, 35, 35]] } ) assert(np.all(res[0] == 11)) assert(np.all(res[1] == 33))
def testcase1(): array = np.random.rand(32, 100, 100, 3) data = tf.convert_to_tensor(array, dtype=tf.float32) rois = tf.convert_to_tensor([[0, 10, 10, 20, 20], [31, 30, 30, 40, 40]], dtype=tf.float32) W = weight_variable([3, 3, 3, 1]) h = conv2d(data, W) [y, argmax] = roi_pooling_op.roi_pool(h, rois, 6, 6, 1.0/3) pdb.set_trace() y_data = tf.convert_to_tensor(np.ones((2, 6, 6, 1)), dtype=tf.float32) print y_data, y, argmax # Minimize the mean squared errors. loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss) init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init) pdb.set_trace() for step in xrange(10): sess.run(train) print(step, sess.run(W)) print(sess.run(y))
for x in xrange(50): for y in xrange(50): for c in xrange(3): array[b,x,y,c] = x+y data = tf.convert_to_tensor(array, dtype=tf.float32) rois_array = [[0, 10, 10, 15, 15], [31, 30, 30, 35, 35]] rois = tf.convert_to_tensor(rois_array, dtype=tf.float32) # W = weight_variable([3, 3, 3, 1]) W = tf.Variable(tf.convert_to_tensor(np.ones((3, 3, 3, 1)), dtype=tf.float32)) h = conv2d(data, W) proposal1 = h[0,10:15,10:15,:] proposal2 = h[31,30:35,30:35,:] pdb.set_trace() [y, argmax] = roi_pooling_op.roi_pool(h, rois, 3, 3, 1.0) pdb.set_trace() y_data = tf.convert_to_tensor(np.ones((2, 3, 3, 2)), dtype=tf.float32) pdb.set_trace() # Minimize the mean squared errors. loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.00001) train = optimizer.minimize(loss) init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init) pdb.set_trace()
def weight_variable(shape): initial = tf.truncated_normal(shape, stddev=0.1) return tf.Variable(initial) def conv2d(x, W): return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME') array = np.random.rand(32, 100, 100, 3) data = tf.convert_to_tensor(array, dtype=tf.float32) rois = tf.convert_to_tensor([[0, 10, 10, 20, 20], [31, 30, 30, 40, 40]], dtype=tf.float32) W = weight_variable([3, 3, 3, 1]) h = conv2d(data, W) [y, argmax] = roi_pooling_op.roi_pool(h, rois, 6, 6, 1.0/3) y_data = tf.convert_to_tensor(np.ones((2, 6, 6, 1)), dtype=tf.float32) print y_data, y, argmax # Minimize the mean squared errors. loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss) init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init) for step in xrange(10):
for x in xrange(50): for y in xrange(50): for c in xrange(3): array[b,x,y,c] = x+y data = tf.convert_to_tensor(array, dtype=tf.float32) rois_array = [[0, 10, 10, 15, 15], [31, 30, 30, 35, 35]] rois = tf.convert_to_tensor(rois_array, dtype=tf.float32) # W = weight_variable([3, 3, 3, 1]) W = tf.Variable(tf.convert_to_tensor(np.ones((3, 3, 3, 1)), dtype=tf.float32)) h = conv2d(data, W) proposal1 = h[0,10:15,10:15,:] proposal2 = h[31,30:35,30:35,:] print proposal1, proposal2 [y, argmax_x, argmax_y] = roi_pooling_op.roi_pool(h, rois, 3, 3, 1.0) pdb.set_trace() y_data = tf.convert_to_tensor(np.ones((2, 3, 3, 2)), dtype=tf.float32) print y, argmax_x, argmax_y # Minimize the mean squared errors. loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss) init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init) pdb.set_trace()
return tf.Variable(initial) def conv2d(x, W): return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME') array = np.random.rand(32, 100, 100, 3) data = tf.convert_to_tensor(array, dtype=tf.float32) rois = tf.convert_to_tensor([[0, 10, 10, 20, 20], [31, 30, 30, 40, 40]], dtype=tf.float32) W = weight_variable([3, 3, 3, 1]) h = conv2d(data, W) [y, argmax] = roi_pooling_op.roi_pool(h, rois, 6, 6, 1.0 / 3) #pdb.set_trace() y_data = tf.convert_to_tensor(np.ones((2, 6, 6, 1)), dtype=tf.float32) print y_data, y, argmax # Minimize the mean squared errors. loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss) init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init) #pdb.set_trace()
ca_roi_input0 = f["ca_roi_input0"].value f1 = h5py.File("ca_roi_input1.h5", 'r') ca_roi_input1 = f1["ca_roi_input1"].value h = tf.convert_to_tensor(ca_roi_input0, dtype=tf.float32) roi_index = np.zeros(shape=(300, 1)) ca_roi_input1 = np.concatenate((roi_index, ca_roi_input1), axis=1) print("========= new ca_roi_input1 ", ca_roi_input1.shape) rois = tf.convert_to_tensor(ca_roi_input1, dtype=tf.float32) print("============== ca_roi_input1.shape:", ca_roi_input1.shape) print("============== ca_roi_input0.shape:", ca_roi_input0.shape) [y, argmax] = roi_pooling_op.roi_pool(h, rois, 7, 7, 0.0625) # y_data = tf.convert_to_tensor(np.ones((2, 6, 6, 1)), dtype=tf.float32) # Minimize the mean squared errors. # loss = tf.reduce_mean(tf.square(y - y_data)) # optimizer = tf.train.GradientDescentOptimizer(0.5) # train = optimizer.minimize(loss) init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init) result = sess.run(y) print("result:", result.shape) with h5py.File("keras_roi_c.h5", "w") as f2:
def conv2d(x, W): return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME') array = np.random.rand(32, 100, 100, 3) data = tf.convert_to_tensor(array, dtype=tf.float32) rois = tf.convert_to_tensor([[0, 10, 10, 20, 20], [31, 30, 30, 40, 40]], dtype=tf.float32) W = weight_variable([3, 3, 3, 1]) h = conv2d(data, W) h = tf.transpose(h, [0, 3, 1, 2]) [y2, argmax] = roi_pooling_op.roi_pool(h, rois, 60, 60, 1.0 / 3) y = tf.transpose(y2, [0, 2, 3, 1]) y_data = tf.convert_to_tensor(np.ones((2, 60, 60, 1)), dtype=tf.float32) #print y_data, y, argmax # Minimize the mean squared errors. loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.1) train = optimizer.minimize(loss) init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init)
import tensorflow as tf import numpy as np import roi_pooling_op op = roi_pooling_op.roi_pool([], [], 7, 6, 1.0 / 3, 0) init = tf.initialize_all_variables() # Launch the graph. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) sess.run(init) sess.run(op)