Example #1
0
# put image in 4D tensor of shape (1, 3, height, width)
    img_ = img.swapaxes(0, 2).swapaxes(1, 2).reshape(1, 3, img_h, img_w)
    filtered_img = f(img_)

# plot original image and first and second components of output
    pylab.subplot(1, 3, 1); pylab.axis('off'); pylab.imshow(img)
    pylab.gray();
# recall that the convOp output (filtered image) is actually a "minibatch",
# of size 1 here, so we take index 0 in the first dimension:
    pylab.subplot(1, 3, 2); pylab.axis('off'); pylab.imshow(filtered_img[0, 0, :, :])
    pylab.subplot(1, 3, 3); pylab.axis('off'); pylab.imshow(filtered_img[0, 1, :, :])

# filter_img.shape = (1,2,img_h,img_w)
    #print type(filtered_img),filtered_img.shape
    #print type(filtered_img[0,0,:,:]),filtered_img[0,0,:,:].shape
#print type(img),img.shape
    #pylab.show()
    ff = filtered_img[0,1,:,:]
    tmp_img = ff.reshape(ff.shape[0]*ff.shape[1])
    #print tmp_img.shape
    tu = []
    tu.append(sign)
    for i in tmp_img:
        tu.append(i)
    #print type(tu),len(tu)
    train_list.append(tu)
print start,end
tdtf.write_content_to_csv(train_list,DataHome + "test1.csv")
print start,end
Example #2
0
if end >= len(piclist):
    end = len(piclist)

for i in range(start,end): #len(piclist)):
    img_route = piclist[i]
    img_route_list = img_route.split(".")
    breed = 1 
    if img_route_list[0] == "cat":
        breed = 0
    else:
        breed = 1
    img = Image.open(open(DataHome + img_data_dir + img_route))
    img_w , img_h = img.size
    #if (img_w < 250) | (img_h < 250) :
    #    continue
    #print "resizing"
    img = img.resize((250,250),Image.ANTIALIAS)
    features = get_feature(img)
    breed_list = [breed]
    img_info = breed_list + features
    #print type(img_info),len(img_info)
    data_set.append(img_info)
print "writing from %d to %d " % (start,end)
#print data_set 
tdtf.write_content_to_csv(data_set,DataHome + data_csv_file)
#print len(features)
#print features
#print features == features
#feature_file = open('color_feature.cPickle','w')
#cPickle.dump(features,feature_file)
Example #3
0
    pylab.subplot(1, 3, 1)
    pylab.axis('off')
    pylab.imshow(img)
    pylab.gray()
    # recall that the convOp output (filtered image) is actually a "minibatch",
    # of size 1 here, so we take index 0 in the first dimension:
    pylab.subplot(1, 3, 2)
    pylab.axis('off')
    pylab.imshow(filtered_img[0, 0, :, :])
    pylab.subplot(1, 3, 3)
    pylab.axis('off')
    pylab.imshow(filtered_img[0, 1, :, :])

    # filter_img.shape = (1,2,img_h,img_w)
    #print type(filtered_img),filtered_img.shape
    #print type(filtered_img[0,0,:,:]),filtered_img[0,0,:,:].shape
    #print type(img),img.shape
    #pylab.show()
    ff = filtered_img[0, 1, :, :]
    tmp_img = ff.reshape(ff.shape[0] * ff.shape[1])
    #print tmp_img.shape
    tu = []
    tu.append(sign)
    for i in tmp_img:
        tu.append(i)
    #print type(tu),len(tu)
    train_list.append(tu)
print start, end
tdtf.write_content_to_csv(train_list, DataHome + "test1.csv")
print start, end
Example #4
0
#!/usr/bin/python

import transform_data_to_format as tdtf

test_l1 = [1,2,3,4,5,6]
test_l2 = [1,2,3,4,5,6]
test_l = (test_l1,test_l2)
tdtf.write_content_to_csv(test_l,"../data/test.csv")
Example #5
0
#!/usr/bin/python

import transform_data_to_format as tdtf

test_l1 = [1, 2, 3, 4, 5, 6]
test_l2 = [1, 2, 3, 4, 5, 6]
test_l = (test_l1, test_l2)
tdtf.write_content_to_csv(test_l, "../data/test.csv")
Example #6
0
    bg = cv2.imread(DataHome + "bg/" + bg_name)
    bg = cv2.cvtColor(bg, cv2.COLOR_BGR2GRAY)
    h, w = bg.shape
    #show the gray img
    #cv2.imshow("w2",img)
    #cv2.waitKey(0)

    #reshape (h,w) to (h*w,)
    bg = bg.reshape(w * h)
    feature = [2]
    for f_v in bg:
        feature.append(f_v)
    features_list.append(feature)

print len(features_list), len(features_list[0]), len(features_list[-1])
tdtf.write_content_to_csv(features_list, feature_filename)
'''
train_index_list = random.sample(range(len(features_list)), len(features_list)/2 )
train_features_list = []
for i in train_index_list:
    train_features_list.append(features_list[i])
valid_features_list = []
for i in range(len(features_list)):
    if i in train_index_list:
        continue
    valid_features_list.append(features_list[i])

print len(train_features_list)
print len(valid_features_list)
tdtf.write_content_to_csv(train_features_list,train_feature_filename)
'''
Example #7
0
    bg = cv2.imread(DataHome + "bg/" + bg_name)
    bg = cv2.cvtColor(bg, cv2.COLOR_BGR2GRAY)
    h, w = bg.shape
    #show the gray img
    #cv2.imshow("w2",img)
    #cv2.waitKey(0)

    #reshape (h,w) to (h*w,) 
    bg=bg.reshape(w*h) 
    feature= [2]
    for f_v in bg:
        feature.append(f_v)
    features_list.append(feature)

print len(features_list),len(features_list[0]),len(features_list[-1])
tdtf.write_content_to_csv(features_list,feature_filename)
'''
train_index_list = random.sample(range(len(features_list)), len(features_list)/2 )
train_features_list = []
for i in train_index_list:
    train_features_list.append(features_list[i])
valid_features_list = []
for i in range(len(features_list)):
    if i in train_index_list:
        continue
    valid_features_list.append(features_list[i])

print len(train_features_list)
print len(valid_features_list)
tdtf.write_content_to_csv(train_features_list,train_feature_filename)
'''