- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I haven't had any success using the official Tensorflow graph transform tool to prepare my model for mvNCCompile conversion.
I'm now attempting to use official guidance for preparing the model https://movidius.github.io/ncsdk/tf_slim.html
I'm having trouble adapting the example code fragment to my model. I'm unsure as to how to adapt the code given to my model.
The given code is:
import numpy as np
import tensorflow as tf
from tensorflow.contrib.slim.nets import inception
slim = tf.contrib.slim
def run(name, image_size, num_classes):
with tf.Graph().as_default():
image = tf.placeholder("float", [1, image_size, image_size, 3], name="input")
with slim.arg_scope(inception.inception_v1_arg_scope()):
logits, _ = inception.inception_v1(image, num_classes, is_training=False, spatial_squeeze=False)
probabilities = tf.nn.softmax(logits)
init_fn = slim.assign_from_checkpoint_fn('inception_v1.ckpt', slim.get_model_variables('InceptionV1'))
with tf.Session() as sess:
init_fn(sess)
saver = tf.train.Saver(tf.global_variables())
saver.save(sess, "output/"+name)
run('inception-v1', 224, 1001)
In particular I'm struggling with the code inside as I don't use arg_scope
with tf.Graph().as_default():
My model is defined as follows. The generator part of the network I'm trying to prepare for inference is called 'a2b_generator'. The input node is 'inputA' and the output node is 'a2b_generator/output_image'. My network takes in a 1, 600, 600, 3 image and outputs an image of the same size.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from functools import partial
import tensorflow as tf
import tensorflow.contrib.slim as slim
conv = partial(slim.conv2d, activation_fn=None)
deconv = partial(slim.conv2d_transpose, activation_fn=None)
relu = tf.nn.relu
lrelu = partial(tf.nn.leaky_relu, alpha=0.2)
batch_norm = partial(slim.batch_norm, scale=True, decay=0.9, epsilon=1e-5, updates_collections=None)
def discriminator(img, scope, dim=64, train=True):
bn = partial(batch_norm, is_training=train)
conv_bn_lrelu = partial(conv, normalizer_fn=bn, activation_fn=lrelu, biases_initializer=None)
with tf.variable_scope(scope + '_discriminator', reuse=tf.AUTO_REUSE):
net = lrelu(conv(img, dim, 4, 2))
net = conv_bn_lrelu(net, dim * 2, 4, 2)
net = conv_bn_lrelu(net, dim * 4, 4, 2)
net = conv_bn_lrelu(net, dim * 8, 4, 1)
net = conv(net, 1, 4, 1)
return net
def generator(img, scope, dim=64, train=True):
bn = partial(batch_norm, is_training=train)
conv_bn_relu = partial(conv, normalizer_fn=bn, activation_fn=relu, biases_initializer=None)
deconv_bn_relu = partial(deconv, normalizer_fn=bn, activation_fn=relu, biases_initializer=None)
def _residule_block(x, dim):
y = conv_bn_relu(x, dim, 3, 1)
y = bn(conv(y, dim, 3, 1))
return y + x
with tf.variable_scope(scope + '_generator', reuse=tf.AUTO_REUSE):
net = conv_bn_relu(img, dim, 7, 1)
net = conv_bn_relu(net, dim * 2, 3, 2)
net = conv_bn_relu(net, dim * 4, 3, 2)
for i in range(9):
net = _residule_block(net, dim * 4)
net = deconv_bn_relu(net, dim * 2, 3, 2)
net = deconv_bn_relu(net, dim, 3, 2)
net = conv(net, 3, 7, 1)
net = tf.nn.tanh(net, name="output_image")
return net
- Tags:
- Tensorflow
Link Copied
![](/skins/images/4399995709D76C02984DDB9A1DB96C28/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page