Py3 and tensorflow setup

@even Pretty sure. It’s just that I included the sample set (which is too small to train with, but the full set is too large for Github). I used the full data set, and it trains to the same level as Theanos.

I should probably update the notebook with the output from training on the full set, since if you don’t see the small comment, it’s easy to be misled.

I’ll post the results in a bit. It will be a little while, I’m using a CPU at the moment.

Edit (Feb 26th): Something is not quite right. It trains, but not as well as the original Theano network. I must have made a mistake somewhere. I’ll post an update when I know what it is.

Edit (Feb 27th): Something is not right in my script. Everything works when using Theano dim ordering, but the conversion to TensorFlow dim ordering is broken. Somewhere… Could use some help.

Thank you @jpuderer for the good job !
I have just read what changes to do in the github.
But, please could you confirm that with your changes in the github link above, we could run both part 1 and part 2 scripts ?

We’ll be using a different approach to using vgg and resnet in part 2, so you’ll probably want to make some changes to your scripts based on them. (The model weights in part 1 don’t work in tensorflow, and theano weight files you’ve saved won’t work with tensorflow either.)

Other than that, just about everything should work fine. You can always switch backends by changing your keras config file, of course.


@Kjeanclaude You would need to maintain two separate sets of weights for running under Theano or TensorFlow, or be constantly converting between the two regularly.

It probably isn’t worth the trouble. I would just pick one (ie. TensorFlow for this course), convert your weights once, and stick with that.

1 Like

OK, good to heard that.
Indeed I was writing something to allow those who want to run the part 1 scripts locally to do it via a docker image. But with your work, I think we would have more advantage to make the necessary conversions and then run part 1 and part 2 scripts on the same installation (through a VM and virtual gpu for local use).
Great job !

Since I didn’t take Part One with you and am still catching up on the MOOC and associated homeworks, it would be ideal to keep the Theano / Python 2 environment separate from the Tensorflow / Python 3 until I develop sufficient facility to port over the older code. What would be the easiest way to create a separate AMI for the new setup so I can continue chugging along on the old stuff?

Everything worked fine except one glitch with my ubuntu machine.

After upgrading drivers, my system acted weird with no launcher and empty desktop. I had to follow this thread to enable unity which fixed the problem:

###Preventing TensorFlow from taking all available GPU memory:


import keras.backend as K
cfg =
cfg.gpu_options.allow_growth = True

limit_mem function in



sess = tf.Session()


config = tf.ConfigProto()
sess = tf.Session(config=config)



If you have updated your part 1 machine to install tensorflow, you may face a “kernel crash” with the following cryptic message during model training while working with the older code:

F tensorflow/stream_executor/cuda/ current context was not created by the StreamExecutor cuda_driver API: 0x3bae650; a CUDA runtime call was likely performed without using a StreamExecutor context

To fix this, update ~/.theanorc to change the device in use from “gpu” to “cpu”.

device = cpu
floatX = float32

Hi @jpuderer !

I have prepared two environments for the part 2 courses, one on Windows 10 and another on Ubuntu (so cpu). The tests on show that they are correctly installed with tensorflow in backend.
But when I run your scripts on for conversion I got the same following error on both OS:
TypeError: Input ‘split_dim’ of ‘Split’ Op has type float32 that does not match expected type of int32.
I have tried to change the type in the built-in file indicated to pass this step but there are some other conversion problem (and I seriously think we should not have to modify the built-in file …)
I think this is due to python 2 --> python 3 conversion problem.

For those interested in there is a cool post on how to perform python 2 --> 3 conversion HERE. (Perhaps should be useful as we run now on python 3)

So, please @jpuderer could you verify and give some hints on ?

@Kjeanclaude Sure. There are likely some problems with my script. I’ll take a look later tonight. In the meantime, maybe we can move any further discussion about my script to github issues:

I don’t want to crowd out any discussion of folks trying to get their setup for Part 2 working.

OK, I got it !

You can just run the setup script again to create another AMI.

95% of the way there with the Python3 / Tensorflow setup, but two small issues:

  1. Getting a “command not found” error when trying to run the $echo line that configures Keras to use Tensorflow, so never properly executed that. This is leading to a JSONDecodeError when I execute “import keras” in the notebooks. Assuming it’s a simple fix - i.e. I’m not running echo correctly.

$echo’{ “image_dim_ordering”: “tf”, “epsilon”: 1e-07, “floatx”: “float32”, “backend”: “tensorflow” }’> ~/.keras/keras.json

  1. When I try to open the jupyter config file to update my password, vim just opens up an empty file. Guessing that it’s not finding the correct file and instead trying to create a new file b/c I’m not in the right directory (executed this in the downloads/cuda folder after installing the new versions of cudnn, tensorflow, bcolz, keras).

vim .jupyter/

Advice on how to fix?

Run the ‘$echo’ command w/o the ‘$’ prefix. If you notice, the command-line prompt is ‘$’. The ‘$’ just indicates that the command should be run on the command-line.

If the file is empty, then it’s not present. You should create a new config file:
$ jupyter notebook --generate-config

Remove the ‘$’ from the front. That’s just copied from the bash prompt - it shouldn’t actually by included in the command; sorry about that!

You should execute that in your home directory. Apologies for missing the cd before it.

In general, configuration files and directories are found in your home dir.

Instead of vim you may want to use nano. I prefer vim but it has a learning curve.

If anyone is using Vim for the first time, this site turns it into a game (only first few levels are free though, but those are enough to get the basics):

Vim Adventures

This post also lists some useful vundle packages for Vim for python development:

Python IDE


Thanks! I removed the $ originally and the command still didn’t work, but now I realize it’s because I lost all the spaces between the parameters when I copied it. Works now and “import keras” is correctly using Tensorflow.