本文整理汇总了Python中detector.Detector.inference方法的典型用法代码示例。如果您正苦于以下问题:Python Detector.inference方法的具体用法?Python Detector.inference怎么用?Python Detector.inference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类detector.Detector
的用法示例。
在下文中一共展示了Detector.inference方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import inference [as 别名]
def __init__(self, modelNb=3):
"""Load the tensorflow model of VGG16-GAP trained on caltech
Keyword arguments:
modelNb -- iteration of the model to consider
"""
dataset_path = '/home/cuda/datasets/perso_db/'
trainset_path = dataset_path+'train.pkl'
testset_path = dataset_path+'test.pkl'
weight_path = '../caffe_layers_value.pickle'
model_path = '../models/perso/model-'+str(modelNb)
# load labels
testset = pickle.load( open(testset_path, "rb") )
self.label_dict = testset.keys()
n_labels = len(self.label_dict)
# Initialize some tensorflow variables
batch_size = 1
self.images_tf = tf.placeholder( tf.float32, [None, 224, 224, 3], name="images")
self.labels_tf = tf.placeholder( tf.int64, [None], name='labels')
detector = Detector( weight_path, n_labels )
c1,c2,c3,c4,conv5, self.conv6, gap, self.output = detector.inference( self.images_tf )
self.classmap = detector.get_classmap( self.labels_tf, self.conv6 )
self.sess = tf.InteractiveSession()
saver = tf.train.Saver()
saver.restore( self.sess, model_path )
示例2: Detector
# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import inference [as 别名]
testset = pd.DataFrame({'image_path': image_paths_test })
trainset['label_name'] = trainset['image_path'].map(lambda x: x.split('/')[-2])
testset['label_name'] = testset['image_path'].map(lambda x: x.split('/')[-2])
trainset['label'] = trainset['label_name'].map( label_dict )
testset['label'] = testset['label_name'].map( label_dict )
train_phase = tf.placeholder( tf.bool )
learning_rate = tf.placeholder( tf.float32, [])
images_tf = tf.placeholder( tf.float32, [None, 224, 224, 3], name="images")
labels_tf = tf.placeholder( tf.int64, [None], name='labels')
detector = Detector(weight_path, n_labels)
p1,p2,p3,p4,conv5, conv6, gap, output = detector.inference(images_tf)
loss_tf = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits( output, labels_tf ))
weights_only = filter( lambda x: x.name.endswith('W:0'), tf.trainable_variables() )
weight_decay = tf.reduce_sum(tf.pack([tf.nn.l2_loss(x) for x in weights_only])) * weight_decay_rate
loss_tf += weight_decay
sess = tf.InteractiveSession()
saver = tf.train.Saver( max_to_keep=50 )
#optimizer = tf.train.RMSPropOptimizer( learning_rate )
optimizer = tf.train.MomentumOptimizer( learning_rate, momentum )
grads_and_vars = optimizer.compute_gradients( loss_tf )
grads_and_vars = [(tf.clip_by_value(gv[0], -5., 5.), gv[1]) for gv in grads_and_vars]
grads_and_vars = map(lambda gv: (gv[0], gv[1]) if ('conv6' in gv[1].name or 'GAP' in gv[1].name) else (gv[0]*0.1, gv[1]), grads_and_vars)
train_op = optimizer.apply_gradients( grads_and_vars )
示例3: listdir
# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import inference [as 别名]
model_path = '../models/caltech256/model-2'
jpg_folder_path = "../img_test"
imgPath = [join(jpg_folder_path, f) for f in listdir(jpg_folder_path) if isfile(join(jpg_folder_path, f))]
# load the caltech model
f = open(model_label_path,"rb")
label_dict = pickle.load(f)
n_labels = len(label_dict)
batch_size = 1
images_tf = tf.placeholder( tf.float32, [None, 224, 224, 3], name="images")
labels_tf = tf.placeholder( tf.int64, [None], name='labels')
detector = Detector( weight_path, n_labels )
c1,c2,c3,c4,conv5, conv6, gap, output = detector.inference( images_tf )
classmap = detector.get_classmap( labels_tf, conv6 )
sess = tf.InteractiveSession()
saver = tf.train.Saver()
saver.restore( sess, model_path )
# Fast forward images & save them
for idx,imgP in enumerate(imgPath):
img = Image.open(imgP)
img = img.resize([224,224])
img = np.array(img)
img = img.reshape(1,224,224,3)