예제 #1
0
import os
import sys
sys.path.append('../') # WSL lib denpendancy
import lib
import caffe
from lib.net_wrapper import net_wrapper

if __name__ == "__main__" :
	
	# original network
	deploy = '../models/vgg16_conv/test.prototxt'
	model  = '../models/vgg16_conv/pre.caffemodel'
	net = net_wrapper(deploy, model)
	
	# fully conv network
	deploy = '../models/vgg16_conv/test_conv.prototxt'
	net_full_conv = net_wrapper(deploy, model)
	
	params = ['fc6', 'fc7', 'fc8']
	fc_params = {pr: (net._net.params[pr][0].data, net._net.params[pr][1].data) for pr in params}
	for fc in params:
		print '{} weights are {} dimensional and biases are {} dimensional'.format(fc, fc_params[fc][0].shape, fc_params[fc][1].shape)	

	params_full_conv = ['fc6-conv', 'fc7-conv', 'fc8-conv']
	conv_params = {pr: (net_full_conv._net.params[pr][0].data, net_full_conv._net.params[pr][1].data) for pr in params_full_conv}

	for conv in params_full_conv:
		print '{} weights are {} dimensional and biases are {} dimensional'.format(conv, conv_params[conv][0].shape, conv_params[conv][1].shape)

	# converted network (fully conv. net)
	for pr, pr_conv in zip(params, params_full_conv) :
예제 #2
0
from lib.pascal_db import pascal_db
from lib.net_wrapper import net_wrapper
from lib.analyzer import analyzer
import numpy as np
from PIL import Image


if __name__ == '__main__' :
	
	pascal = pascal_db('val','2012','/data/PASCAL/VOCdevkit/', 'cls')
	#arch = 'segmentation/stride_32_only_label'
	arch = 'segmentation/cls_net'
	deploy = '../models/' + arch + '/test.prototxt'
	#model  = '../models/' + arch + '/finetuned_models/alex_ift_iter_1500.caffemodel'
	model  = '../models/' + arch + '/finetuned_models/ftmodels_iter_3000.caffemodel'
	net = net_wrapper(deploy, model,3)
	#net = analyzer(deploy, model)
	for i, ind in enumerate(pascal._image_index) :
		image_path = os.path.join( pascal._data_path, 'JPEGImages', ind + pascal._image_ext )
		net.run_forward(image_path)
		res = net._output['prob']
		#res = net._output['pool-global']
		res = res.squeeze()
		res = res[np.newaxis,:]
		if i == 0 :
			final_res = np.copy(res)
		else :
			final_res = np.vstack((final_res,res))
		print '{:d} th image ... {:s}'.format(i+1, ind)
	# wrote the results
	pascal.write_voc_results_files(final_res)
예제 #3
0
import matplotlib.pyplot as plt
import scipy


if __name__ == '__main__' :

	gpu_id = sys.argv[1]
	arch = sys.argv[2]
	setting = sys.argv[3]

	# load pascal db
	pascal = pascal_db('val','2012','/data/PASCAL/VOCdevkit/', 'seg')
	
	deploy = './0__MODELS/' + arch + '/' + setting + '/test.prototxt'
	model  = './0__MODELS/' + arch + '/' + setting + '/ft_models/final.caffemodel'
	net = net_wrapper(deploy, model, int(gpu_id))
	
	comp_id = setting
	save_path = os.path.join(pascal._devkit_path, 'results', 'VOC' + pascal._year, 'Segmentation', comp_id + '_' + pascal._image_set + '_cls' )
	if not os.path.exists( save_path ) :
		os.makedirs( save_path )
	
	for i, ind in enumerate(pascal._image_index) :
		image_path = os.path.join( pascal._data_path, 'JPEGImages', ind + pascal._image_ext )
		net.run_forward(image_path)
		res = net._output['prob']
		label_map = np.argmax(res[0],axis=0).astype(np.uint8)
		gt_path = os.path.join( pascal._data_path, 'SegmentationClass', ind + '.png' )
		gt = Image.open(gt_path)
		res_map = scipy.misc.toimage(label_map, pal=pascal._color_map, mode='P')
		res_map = res_map.resize( gt.size, Image.NEAREST )