示例#1
0
import matplotlib.pyplot as plt
import sys, os
from collections import OrderedDict
from itertools import product

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from sample_maker import create_pos, create_neg
#from sc import sc
from sc_freeze import sc

input_shape = (8, 8)
batch_size = 1
ch = 3

neg = create_neg(input_shape)[None, :, :, :]
pos = create_pos(input_shape)[None, :, :, :]

inputs = tf.placeholder(tf.float32,
                        shape=(batch_size, input_shape[0], input_shape[1], 1))
modify = []
for i in range(1, 4):
    modify.append('conv%d' % i)

logits, net, activations, modifys = sc(inputs, modify=modify)
print modifys
modifyv = {}
for i in range(1, 4):
    name = 'conv%d' % i
    print name
    modifyv[name] = np.ones(activations[name].shape)
with tf.Session() as sess:
示例#2
0
batch_size = 50
input_shape = (8, 8)

inputs = tf.placeholder(tf.float32,
                        shape=(batch_size, input_shape[0], input_shape[1], 1))
labels = tf.placeholder(tf.float32, shape=(batch_size, None, None, None))
logits, net, activations = sc(inputs)

sess = tf.InteractiveSession()
saver = tf.train.Saver()
#sess.run(tf.global_variables_initializer())
#saver.restore(sess,'ckpts_freeze/20000.ckpt')

neg = create_neg(input_shape)[:, :, :]
pos = create_pos(input_shape)[:, :, :]
poss = np.array([pos for _ in xrange(batch_size)])
negs = np.array([neg for _ in xrange(batch_size)])

trainingv = ['conv%d/weights:0' % j for j in xrange(1, 4)]
trr = [tv for tv in tf.trainable_variables() if tv.name in trainingv]
labelss = {}
for j in range(1, 4):
    labelss['conv%d' % j] = tf.placeholder(
        tf.float32, shape=activations['conv%d' % j].get_shape().as_list())
    loss = tf.losses.mean_squared_error(labelss['conv%d' % j],
                                        activations['conv%d' % j],
                                        weights=100. / j**2)
    tf.losses.add_loss(loss)
total_loss = tf.losses.get_total_loss()
#loss = tf.losses.softmax_cross_entropy(labels,activations['conv%d'%j],weights=10)