Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
TensorFlow 1.x Deep Learning Cookbook

You're reading from  TensorFlow 1.x Deep Learning Cookbook

Product type Book
Published in Dec 2017
Publisher Packt
ISBN-13 9781788293594
Pages 536 pages
Edition 1st Edition
Languages
Toc

Table of Contents (15) Chapters close

Preface 1. TensorFlow - An Introduction 2. Regression 3. Neural Networks - Perceptron 4. Convolutional Neural Networks 5. Advanced Convolutional Neural Networks 6. Recurrent Neural Networks 7. Unsupervised Learning 8. Autoencoders 9. Reinforcement Learning 10. Mobile Computation 11. Generative Models and CapsNet 12. Distributed TensorFlow and Cloud Deep Learning 13. Learning to Learn with AutoML (Meta-Learning) 14. TensorFlow Processing Units

Migrating from 0.x to 1.x

TensorFlow 1.x does not offer backward compatibility. This means that the codes that worked on TensorFlow 0.x may not work on TensorFlow 1.0. So, if you have codes that worked on TensorFlow 0.x, you need to upgrade them (old GitHub repositories or your own codes). This recipe will point out major differences between TensorFlow 0.x and TensorFlow 1.0 and will show you how to use the script tf_upgrade.py to automatically upgrade the code for TensorFlow 1.0.

How to do it...

Here is how we proceed with the recipe:

  1. First, download tf_upgrade.py from https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/compatibility.
  2. If you want to convert one file from TensorFlow 0.x to TensorFlow 1.0, use the following command at the command line:
python tf_upgrade.py --infile old_file.py --outfile upgraded_file.py
  1. For example, if you have a TensorFlow program file named test.py, you will use the preceding command as follows:
python tf_upgrade.py --infile test.py --outfile test_1.0.py
  1. This will result in the creation of a new file named test_1.0.py.
  2. If you want to migrate all the files of a directory, then use the following at the command line:
python tf_upgrade.py --intree InputDIr --outtree OutputDir
# For example, if you have a directory located at /home/user/my_dir you can migrate all the python files in the directory located at /home/user/my-dir_1p0 using the above command as:
python tf_upgrade.py --intree /home/user/my_dir --outtree /home/user/my_dir_1p0

  1. In most cases, the directory also contains dataset files; you can ensure that non-Python files are copied as well in the new directory (my-dir_1p0 in the preceding example) using the following:
python tf_upgrade.py --intree /home/user/my_dir --outtree /home/user/my_dir_1p0 -copyotherfiles True
  1. In all these cases, a report.txt file is generated. This file contains the details of conversion and any errors in the process.
  2. Read the report.txt file and manually upgrade the part of the code that the script is unable to update.

There's more...

tf_upgrade.py has certain limitations:

  • It cannot change the arguments of tf.reverse(): you will have to manually fix it
  • For methods with argument list reordered, like tf.split() and tf.reverse_split(), it will try to introduce keyword arguments, but it cannot actually reorder the arguments
  • You will have to manually replace constructions like tf.get.variable_scope().reuse_variables() with the following:
with tf.variable_scope(tf.get_variable_scope(), resuse=True):
You have been reading a chapter from
TensorFlow 1.x Deep Learning Cookbook
Published in: Dec 2017 Publisher: Packt ISBN-13: 9781788293594
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime