In [1]:
import tensorflow as tf
import numpy as np
import os
from nets import inception
from datasets import imagenet
#import urllib.request as urllib
#from preprocessing import inception_preprocessing,preprocessing_factory
import model
import myreader
from matplotlib import pyplot as plt
slim = tf.contrib.slim
from PIL import Image
import time

In [2]:
file_dir = "../local/images/val2017"
image_batch, _ = myreader.input_pipeline(file_dir, batch_size = 2, num_epochs = 1,IsRecord = False)
#raw_images = tf.cast(image_batch, tf.float32)
raw_images = image_batch
gen_images = model.net(raw_images, training = True)
gen_images = tf.image.resize_images(gen_images,[299,299])

image_path = '../local/style_cubist.jpg'
style_iamge = tf.read_file(image_path)

#feature = get_style_features()
style_image = tf.image.decode_jpeg(style_iamge, channels=3) 
style_image = tf.image.resize_images(style_image,[299, 299])
style_image = tf.expand_dims(style_image, 0)
style_image = tf.cast(style_image, tf.float32) * (1. / 255) - 0.5

In [ ]:
image_batch

In [3]:
with slim.arg_scope(inception.inception_v4_arg_scope()):
    _, style_endpoint = inception.inception_v4(style_image, num_classes=1001, is_training=False, reuse=None)

with slim.arg_scope(inception.inception_v4_arg_scope()):
    _, content_endpoint = inception.inception_v4(raw_images, num_classes=1001, is_training=False, reuse=True)



checkpoints_dir = '../local'
init_fn = slim.assign_from_checkpoint_fn(
    os.path.join(checkpoints_dir, 'inception_v4.ckpt'),
    slim.get_model_variables('InceptionV4'))

In [ ]:
gen_images

In [4]:
with slim.arg_scope(inception.inception_v4_arg_scope()):
    _, gen_endpoint = inception.inception_v4(gen_images, num_classes=1001, is_training=False, reuse=True)

In [5]:
#"""
def gram(layer):
    shape = tf.shape(layer)
    num_images = shape[0]
    width = shape[1]
    height = shape[2]
    num_filters = shape[3]
    filters = tf.reshape(layer, tf.stack([num_images, -1, num_filters]))
    grams = tf.matmul(filters, filters, adjoint_a = True) / tf.to_float(width * height * num_filters)
    return grams

"""
def gram(features):
    shape = tf.shape(layer)
    num_images = shape[0]
    width = shape[1]
    height = shape[2]
    num_filters = shape[3]
    filters = tf.reshape(layer, tf.pack([num_images, -1, num_filters]))
    grams = tf.batch_matmul(filters, filters, adj_x=True) / tf.to_float(width * height * num_filters)
    return grams
"""
def gram_vector(filter_vector):
    shape = tf.shape(filter_vector)
    num_images = shape[0]
    num_filters = shape[1]
    reshape_a = tf.expand_dims(filter_vector, 1)
    #reshape_b = tf.expand_dims(filter_vector, 2)
    grams = tf.matmul(reshape_a, reshape_a, adjoint_a = True) / tf.to_float(num_images * num_filters)
    return grams

In [6]:
def style_loss(style_gram, gen):
    size = tf.size(style_gram)
    layer_style_loss = tf.nn.l2_loss(gram(gen) - style_gram) * 2 / tf.to_float(size)
    return layer_style_loss

In [7]:
def content_loss(gen, content):

    size = tf.size(gen)
    content_loss = tf.nn.l2_loss(gen - content) * 2 / tf.to_float(size)  # remain the same as in the paper
    return content_loss

In [8]:
style_style_features = style_endpoint['Mixed_6a']
style_style_pool = tf.nn.max_pool(style_style_features, [1, 3, 3, 1],[1, 3, 3, 1], padding='SAME', name=None)
style_style_gram = gram(style_style_pool)

gen_style_features = gen_endpoint['Mixed_6a']
content_content_features = content_endpoint['PreLogitsFlatten']
gen_content_feature = gen_endpoint['PreLogitsFlatten']

Sloss = style_loss(style_style_gram, gen_style_features)
Closs = content_loss(content_content_features, gen_content_feature)
loss = (0.2 * Sloss) + (0.8 * Closs)

In [13]:
"""Prepare to Train"""
global_step = tf.Variable(0, name="global_step", trainable=False)

variable_to_train = []

for variable in tf.trainable_variables():
    if not(variable.name.startswith('InceptionV4')):
        variable_to_train.append(variable)
train_op = tf.train.AdamOptimizer(1e-3).minimize(loss, global_step=global_step, var_list=variable_to_train)

saver = tf.train.Saver(var_list = variable_to_train)

In [10]:
for key in style_endpoint:
    print(key,style_endpoint[key].shape)


Mixed_6h (1, 17, 17, 1024)
Mixed_5c (1, 35, 35, 384)
Conv2d_1a_3x3 (1, 149, 149, 32)
PreLogitsFlatten (1, 1536)
Mixed_7a (1, 8, 8, 1536)
Mixed_5a (1, 35, 35, 384)
Predictions (1, 1001)
Mixed_6d (1, 17, 17, 1024)
Mixed_6g (1, 17, 17, 1024)
Mixed_7b (1, 8, 8, 1536)
Mixed_4a (1, 71, 71, 192)
Mixed_6c (1, 17, 17, 1024)
Mixed_7c (1, 8, 8, 1536)
Mixed_7d (1, 8, 8, 1536)
Mixed_6b (1, 17, 17, 1024)
Conv2d_2b_3x3 (1, 147, 147, 64)
Logits (1, 1001)
Mixed_5e (1, 35, 35, 384)
Mixed_5b (1, 35, 35, 384)
Mixed_3a (1, 73, 73, 160)
Conv2d_2a_3x3 (1, 147, 147, 32)
Mixed_6a (1, 17, 17, 1024)
Mixed_5d (1, 35, 35, 384)
Mixed_6e (1, 17, 17, 1024)
Mixed_6f (1, 17, 17, 1024)
AuxLogits (1, 1001)

In [15]:
with tf.Session() as sess:
    
    sess.run([tf.global_variables_initializer(),tf.local_variables_initializer()])
    init_fn(sess)
    coord=tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    start_time = time.time()
    
    for _ in range(10):    
        _, loss_t, step,gens = sess.run([train_op, loss, global_step,gen_images])
        elapsed_time = time.time() - start_time
        start_time = time.time()
        if step % 5 == 0:
            tf.logging.info('step: %d,  total Loss %f, secs/step: %f' % (step, loss_t, elapsed_time))

            plt.figure()
            plt.imshow(gens[0].astype(np.uint8))
            plt.show()
            saver.save(sess, 'my-model', global_step=step)
    #gen = sess.run(gen_images)
    coord.request_stop()
    coord.join(threads)


INFO:tensorflow:Restoring parameters from ../local\inception_v4.ckpt
INFO:tensorflow:step: 5,  total Loss 3.629174, secs/step: 0.995803
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-5e25f7dc50a9> in <module>()
     18             plt.imshow(gens[0].astype(np.uint8))
     19             plt.show()
---> 20             saver.save(sess, 'my-model', global_step=step)
     21     #gen = sess.run(gen_images)
     22     coord.request_stop()

E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\training\saver.py in save(self, sess, save_path, global_step, latest_filename, meta_graph_suffix, write_meta_graph, write_state)
   1380     if not gfile.IsDirectory(os.path.dirname(save_path)):
   1381       raise ValueError(
-> 1382           "Parent directory of {} doesn't exist, can't save.".format(save_path))
   1383 
   1384     save_path = os.path.dirname(save_path)

ValueError: Parent directory of my-model doesn't exist, can't save.
INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.CancelledError'>, Enqueue operation was cancelled
	 [[Node: shuffle_batch/random_shuffle_queue_enqueue = QueueEnqueueV2[Tcomponents=[DT_FLOAT, DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, sub/_1305, ReaderReadV2)]]

Caused by op 'shuffle_batch/random_shuffle_queue_enqueue', defined at:
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start
    super(ZMQIOLoop, self).start()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tornado\ioloop.py", line 888, in start
    handler_func(fd_obj, events)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\kernelbase.py", line 235, in dispatch_shell
    handler(stream, idents, msg)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\kernelbase.py", line 399, in execute_request
    user_expressions, allow_stdin)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\IPython\core\interactiveshell.py", line 2802, in run_ast_nodes
    if self.run_code(code, result):
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-32ca1a493f53>", line 3, in <module>
    image_batch, _ = myreader.input_pipeline(file_dir, batch_size = 2, num_epochs = 1,IsRecord = False)
  File "E:\GitHub\nerual_style_transfer\myreader.py", line 82, in input_pipeline
    min_after_dequeue=min_after_dequeue)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\training\input.py", line 1214, in shuffle_batch
    name=name)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\training\input.py", line 770, in _shuffle_batch
    _enqueue(queue, tensor_list, num_threads, enqueue_many, keep_input)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\training\input.py", line 679, in _enqueue
    control_flow_ops.no_op)] * threads
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\training\input.py", line 418, in _smart_cond
    return if_true()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\training\input.py", line 678, in <lambda>
    lambda: enqueue_fn(tensor_list),
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\ops\data_flow_ops.py", line 322, in enqueue
    self._queue_ref, vals, name=scope)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\ops\gen_data_flow_ops.py", line 1587, in _queue_enqueue_v2
    name=name)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 768, in apply_op
    op_def=op_def)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\framework\ops.py", line 2336, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\framework\ops.py", line 1228, in __init__
    self._traceback = _extract_stack()

CancelledError (see above for traceback): Enqueue operation was cancelled
	 [[Node: shuffle_batch/random_shuffle_queue_enqueue = QueueEnqueueV2[Tcomponents=[DT_FLOAT, DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, sub/_1305, ReaderReadV2)]]


In [ ]:


In [ ]:
gen[0]

In [ ]:
def total_variation_loss(layer):
    shape = tf.shape(layer)
    height = shape[1]
    width = shape[2]
    y = tf.slice(layer, [0,0,0,0], tf.pack([-1,height-1,-1,-1])) - tf.slice(layer, [0,1,0,0], [-1,-1,-1,-1])
    x = tf.slice(layer, [0,0,0,0], tf.pack([-1,-1,width-1,-1])) - tf.slice(layer, [0,0,1,0], [-1,-1,-1,-1])
    return tf.nn.l2_loss(x) / tf.to_float(tf.size(x)) + tf.nn.l2_loss(y) / tf.to_float(tf.size(y))

In [ ]:
def get_style_features(style_paths):
    image = tf.image.decode_jpeg(style_paths, channels=3) 
    with slim.arg_scope(inception.inception_v4_arg_scope()):
        logits, endpoint = inception.inception_v4(raw_imgs, num_classes=1001, is_training=True, reuse=True)
    features = endpoint['PreLogitsFlatten']
    return features

In [ ]:

读取图片并测试损失网络


In [6]:
file_dir = "../local"
img_batch, labels = myreader.input_pipeline(file_dir, batch_size = 5, num_epochs = 1,IsRecord = True)
raw_imgs = tf.cast(img_batch, tf.float32)
gen_imgs = model.net(raw_imgs, training = True)   

checkpoints_dir = '../local'

In [ ]:
with slim.arg_scope(inception.inception_v4_arg_scope()):
        logits, endpoint = inception.inception_v4(raw_imgs, num_classes=1001, is_training=True, reuse = False)
probabilities = tf.nn.softmax(logits)

init_fn = slim.assign_from_checkpoint_fn(
        os.path.join(checkpoints_dir, 'inception_v4.ckpt'),
        slim.get_model_variables('InceptionV4'))

In [7]:
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    sess.run(tf.local_variables_initializer())
    coord=tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    init_fn(sess)
    np_image, out_probabilities ,out_endpoints = sess.run([img_batch, probabilities,endpoint])
    print(out_endpoints['PreLogitsFlatten'])
    #out_probabilities = out_probabilities[0, 0:]
    for k in range(5):
        iprobilities = out_probabilities[k, 0:]
        sorted_inds = [i[0] for i in sorted(enumerate(-iprobilities), key=lambda x:x[1])]
        plt.figure() 
        plt.imshow(np_image[k].astype(np.uint8))
        plt.axis('off')
        plt.show()
        print("start prediction")
        names = imagenet.create_readable_names_for_imagenet_labels()
        for i in range(5):
            index = sorted_inds[i]
            print('Probability %0.2f%% => [%s]' % (iprobilities[index] * 100, names[index]))

    coord.request_stop()
    coord.join(threads)


INFO:tensorflow:Restoring parameters from ../local\inception_v4.ckpt
---------------------------------------------------------------------------
OutOfRangeError                           Traceback (most recent call last)
E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1038     try:
-> 1039       return fn(*args)
   1040     except errors.OpError as e:

E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\client\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
   1020                                  feed_dict, fetch_list, target_list,
-> 1021                                  status, run_metadata)
   1022 

E:\ProgramData\Anaconda3\envs\tfxgb\lib\contextlib.py in __exit__(self, type, value, traceback)
     65             try:
---> 66                 next(self.gen)
     67             except StopIteration:

E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status()
    465           compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466           pywrap_tensorflow.TF_GetCode(status))
    467   finally:

OutOfRangeError: RandomShuffleQueue '_7_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 5, current size 0)
	 [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_UINT8], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

During handling of the above exception, another exception occurred:

OutOfRangeError                           Traceback (most recent call last)
<ipython-input-7-507d165a9c0a> in <module>()
      5     threads = tf.train.start_queue_runners(coord=coord)
      6     init_fn(sess)
----> 7     np_image, out_probabilities ,out_endpoints = sess.run([img_batch, probabilities,endpoint])
      8     print(out_endpoints['PreLogitsFlatten'])
      9     #out_probabilities = out_probabilities[0, 0:]

E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
    776     try:
    777       result = self._run(None, fetches, feed_dict, options_ptr,
--> 778                          run_metadata_ptr)
    779       if run_metadata:
    780         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
    980     if final_fetches or final_targets:
    981       results = self._do_run(handle, final_targets, final_fetches,
--> 982                              feed_dict_string, options, run_metadata)
    983     else:
    984       results = []

E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1030     if handle is None:
   1031       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1032                            target_list, options, run_metadata)
   1033     else:
   1034       return self._do_call(_prun_fn, self._session, handle, feed_dict,

E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1050         except KeyError:
   1051           pass
-> 1052       raise type(e)(node_def, op, message)
   1053 
   1054   def _extend_graph(self):

OutOfRangeError: RandomShuffleQueue '_7_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 5, current size 0)
	 [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_UINT8], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

Caused by op 'shuffle_batch', defined at:
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start
    super(ZMQIOLoop, self).start()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tornado\ioloop.py", line 888, in start
    handler_func(fd_obj, events)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\kernelbase.py", line 235, in dispatch_shell
    handler(stream, idents, msg)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\kernelbase.py", line 399, in execute_request
    user_expressions, allow_stdin)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\IPython\core\interactiveshell.py", line 2802, in run_ast_nodes
    if self.run_code(code, result):
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-6631368ef764>", line 2, in <module>
    img_batch, labels = myreader.input_pipeline(file_dir, batch_size = 5, num_epochs = 1,IsRecord = True)
  File "E:\GitHub\nerual_style_transfer\myreader.py", line 79, in input_pipeline
    [img, label], batch_size=batch_size, capacity=capacity,
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\training\input.py", line 1214, in shuffle_batch
    name=name)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\training\input.py", line 784, in _shuffle_batch
    dequeued = queue.dequeue_many(batch_size, name=name)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\ops\data_flow_ops.py", line 458, in dequeue_many
    self._queue_ref, n=n, component_types=self._dtypes, name=name)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\ops\gen_data_flow_ops.py", line 1328, in _queue_dequeue_many_v2
    timeout_ms=timeout_ms, name=name)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 768, in apply_op
    op_def=op_def)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\framework\ops.py", line 2336, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "E:\ProgramData\Anaconda3\envs\tfxgb\lib\site-packages\tensorflow\python\framework\ops.py", line 1228, in __init__
    self._traceback = _extract_stack()

OutOfRangeError (see above for traceback): RandomShuffleQueue '_7_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 5, current size 0)
	 [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_UINT8], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

In [ ]:
for key in out_endpoints:
    print(key)
    pass
out_endpoints["PreLogitsFlatten"][0]

生成模型测试


In [ ]:
with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        sess.run(tf.local_variables_initializer())
        coord=tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)
        print(file_dir)
        for _ in range(3):
            val = sess.run(gen_imgs)
            raw_batch = sess.run(img_batch)
            #print(type(raw_batch))
            plt.figure()
            plt.imshow(val[0])
            plt.axis('off')
            plt.show()
            
            plt.figure()
            plt.imshow(raw_batch[0])
            plt.axis('off')
            plt.show()
    
        coord.request_stop()
        coord.join(threads)

In [ ]: