-
Notifications
You must be signed in to change notification settings - Fork 4
/
DPSH_model.py
24 lines (20 loc) · 1012 Bytes
/
DPSH_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- coding: utf-8 -*-
import tensorflow as tf
import vggf
class model(object):
"""The PTB model."""
def __init__(self, config):
self.im_raw = im_raw = tf.placeholder('float32', [None, 32, 32, 3])
im_resize = tf.image.resize_images(im_raw, 224, 224)
net, _,_ = vggf.construct_net(config.vgg_path, im_resize, config.codelens)
self.net = net
self.S =S = tf.placeholder('float32', [None, None])
self.lrx = lrx = tf.placeholder('float32', ())
self.Ux = Ux = tf.placeholder('float32', [None,config.codelens])
U0 = net['fc8']
theta = tf.mul(1.0 / 2, tf.matmul(U0, tf.transpose(Ux)))
B_code = tf.sign(U0)
loss = tf.div(
(- 2.0 * tf.reduce_sum(tf.mul(S, theta) - (tf.max(0,theta)+tf.log(tf.exp(tf.abs(-theta))+1)))) + config.lamda * tf.reduce_sum(tf.pow((B_code - U0), 2)),
float(config.N_size*config.batch_size))
self.train_step = tf.train.GradientDescentOptimizer(lrx).minimize(loss)