By Enyang Wang


2019-08-13 20:18:29 8 Comments

I get the error message that session graph is empty.. I have looked into different questions on stackoverflow page but nothing worked for me..

import os
import sys
import scipy.io
import scipy.misc
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
from PIL import Image
from nst_utils import *
import numpy as np
import tensorflow as tf

model = load_vgg_model("imagenet-vgg-verydeep-19.mat")

tf.reset_default_graph()

# Start interactive session
sess = tf.InteractiveSession()

content_image = scipy.misc.imresize(arr = scipy.misc.imread("content.jpeg"), size=(300,400,3))
content_image = reshape_and_normalize_image(content_image)

style_image = scipy.misc.imresize(arr = scipy.misc.imread("monet.jpg"), size=(300,400,3))
style_image = reshape_and_normalize_image(style_image)

generated_image = generate_noise_image(content_image)
imshow(generated_image[0])

# Assign the content image to be the input of the VGG model.  
with tf.Session() as sess:
    sess.run(model['input'].assign(content_image))

I get "RuntimeError: The Session graph is empty. Add operations to the graph before calling run()." Appreciate every advise I can get :)

1 comments

@gorjan 2019-08-13 20:38:07

A couple of errors:

  1. You are instantiating a model model = load_vgg_model("imagenet-vgg-verydeep-19.mat") then reseting the default graph tf.reset_default_graph() → it should be the other way around.
  2. You have one tf.InteractiveSession() started and you are creating another tf.Session() → You don't need the first one.

This should work for you:

import os import sys import scipy.io import scipy.misc import matplotlib.pyplot as plt from matplotlib.pyplot import imshow from PIL import Image from nst_utils import * import numpy as np import tensorflow as tf

tf.reset_default_graph()
model = load_vgg_model("imagenet-vgg-verydeep-19.mat")

content_image = scipy.misc.imresize(arr = scipy.misc.imread("content.jpeg"), size=(300,400,3))
content_image = reshape_and_normalize_image(content_image)

style_image = scipy.misc.imresize(arr = scipy.misc.imread("monet.jpg"), size=(300,400,3))
style_image = reshape_and_normalize_image(style_image)

generated_image = generate_noise_image(content_image)
imshow(generated_image[0])

# Assign the content image to be the input of the VGG model.  
sess = tf.InteractiveSession()
sess.run(model['input'].assign(content_image))

@Enyang Wang 2019-08-13 20:47:59

hi! thanks for all the advises, much appreciation! :) if i prefer to have the sess = tf.InteractiveSession() at the beginning, then I wouldnt need the 'with tf.Session() as sess:" statement, right?

@gorjan 2019-08-13 20:55:29

I updated my answer based on your feedback. Yes, you wouldn't need it. Assuming that your other functions are in order, this should work.

@Enyang Wang 2019-08-13 22:12:59

thanks a lot, much appreciation!

Related Questions

Sponsored Content

13 Answered Questions

[SOLVED] How do I expire a PHP session after 30 minutes?

  • 2009-02-06 13:14:14
  • Tom
  • 929513 View
  • 1017 Score
  • 13 Answer
  • Tags:   php session cookies

26 Answered Questions

[SOLVED] Check if PHP session has already started

1 Answered Questions

[SOLVED] graph session empty error in Keras with Tensorflow backend

1 Answered Questions

14 Answered Questions

[SOLVED] How to save and restore multiple different sessions in Vim?

  • 2009-10-29 09:53:04
  • Jogusa
  • 80202 View
  • 363 Score
  • 14 Answer
  • Tags:   session vim

6 Answered Questions

[SOLVED] Do sessions really violate RESTfulness?

Sponsored Content