You are on page 1of 66

12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Log in Create Account

Karlijn Willems
January 16th, 2019

MUST READ PYTHON +4

TensorFlow Tutorial For Beginners


Learn how to build a neural network and how to train, evaluate and
optimize it with TensorFlow

Deep learning is a sub eld of machine learning that is a set of algorithms that is inspired by
the structure and function of the brain.

TensorFlow is the second machine learning framework that Google created and used to
design, build, and train deep learning models. You can use the TensorFlow library do to
numerical computations,
Want which in itself doesn’t seem all too special, but these computations
to leave a comment?
are done with data ow graphs. In these graphs, nodes represent mathematical operations,
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 1/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

while the edges represent the data, which usually are multidimensional data arrays or
tensors, that are communicated between these edges.

You see? The name “TensorFlow” is derived from the operations which neural networks
perform on multidimensional data arrays or tensors! It’s literally a ow of tensors. For now,
this is all you need to know about tensors, but you’ll go deeper into this in the next sections!

Today’s TensorFlow tutorial for beginners will introduce you to performing deep learning in
an interactive way:

You’ll rst learn more about tensors;

Then, the tutorial you’ll brie y go over some of the ways that you can install TensorFlow
on your system so that you’re able to get started and load data in your workspace;

After this, you’ll go over some of the TensorFlow basics: you’ll see how you can easily get
started with simple computations.

After this, you get started on the real work: you’ll load in data on Belgian traf c signs and
exploring it with simple statistics and plotting.

In your exploration, you’ll see that there is a need to manipulate your data in such a way
that you can feed it to your model. That’s why you’ll take the time to rescale your images
and convert them to grayscale.

Next, you can nally get started on your neural network model! You’ll build up your model
layer per layer;

Once the architecture is set up, you can use it to train your model interactively and to
eventually also evaluate it by feeding some test data to it.

Lastly, you’ll get some pointers for further improvements that you can do to the model you
just constructed and how you can continue your learning with TensorFlow.

Download the notebook of this tutorial here.

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 2/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Also, you could be interested in a course on Deep Learning in Python, DataCamp's Keras
tutorial or the keras with R tutorial.

Introducing Tensors
To understand tensors well, it’s good to have some working knowledge of linear algebra and
vector calculus. You already read in the introduction that tensors are implemented in
TensorFlow as multidimensional data arrays, but some more introduction is maybe needed in
order to completely grasp tensors and their use in machine learning.

Plane Vectors

Before you go into plane vectors, it’s a good idea to shortly revise the concept of “vectors”;
Vectors are special types of matrices, which are rectangular arrays of numbers. Because
vectors are ordered collections of numbers, they are often seen as column matrices: they
have just one column and a certain number of rows. In other terms, you could also consider
vectors as scalar magnitudes that have been given a direction.

Remember: an example of a scalar is “5 meters” or “60 m/sec”, while a vector is, for example,
“5 meters north” or “60 m/sec East”. The difference between these two is obviously that the
vector has a direction. Nevertheless, these examples that you have seen up until now might
seem far off from the vectors that you might encounter when you’re working with machine
learning problems. This is normal; The length of a mathematical vector is a pure number: it is
absolute. The direction, on the other hand, is relative: it is measured relative to some
reference direction and has units of radians or degrees. You usually assume that the
direction is positive and in counterclockwise rotation from the reference direction.

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 3/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Visually, of course, you represent vectors as arrows, as you can see in the picture above. This
means that you can consider vectors also as arrows that have direction and length. The
direction is indicated by the arrow’s head, while the length is indicated by the length of the
arrow.

So what about plane vectors then?

Plane vectors are the most straightforward setup of tensors. They are much like regular
vectors as you have seen above, with the sole difference that they nd themselves in a vector
space. To understand this better, let’s start with an example: you have a vector that is 2 X 1.
This means that the vector belongs to the set of real numbers that come paired two at a
time. Or, stated differently, they are part of two-space. In such cases, you can represent
vectors on the coordinate (x,y) plane with arrows or rays.

Working from this coordinate plane in a standard position where vectors have their endpoint
at the origin (0,0), you can derive the x coordinate by looking at the rst row of the vector,
while you’ll nd the y coordinate in the second row. Of course, this standard position doesn’t
always need to be maintained: vectors can move parallel to themselves in the plane without
experiencing changes.

Note that similarly, for vectors that are of size 3 X 1, you talk about the three-space. You can
represent the vector as a three-dimensional gure with arrows pointing to positions in the
Want to leave a comment?
vectors pace: they are drawn on the standard x, y and z axes.

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 4/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

It’s nice to have these vectors and to represent them on the coordinate plane, but in essence,
you have these vectors so that you can perform operations on them and one thing that can
help you in doing this is by expressing your vectors as bases or unit vectors.

Unit vectors are vectors with a magnitude of one. You’ll often recognize the unit vector by a
lowercase letter with a circum ex, or “hat”. Unit vectors will come in convenient if you want
to express a 2-D or 3-D vector as a sum of two or three orthogonal components, such as the
x− and y−axes, or the z−axis.

And when you are talking about expressing one vector, for example, as sums of components,
you’ll see that you’re talking about component vectors, which are two or more vectors whose
sum is that given vector.

Tip: watch this video, which explains what tensors are with the help of simple household
objects!

Tensors

Next to plane vectors, also covectors and linear operators are two other cases that all three
together have one thing in common: they are speci c cases of tensors. You still remember
how a vector was characterized in the previous section as scalar magnitudes that have been
given a direction. A tensor, then, is the mathematical representation of a physical entity that
may be characterized by magnitude and multiple directions.

And, just like you represent a scalar with a single number and a vector with a sequence of
three numbers in a 3-dimensional space, for example, a tensor can be represented by an
array of 3R numbers in a 3-dimensional space.

The “R” in this notation represents the rank of the tensor: this means that in a 3-dimensional
space, a second-rank tensor can be represented by 3 to the power of 2 or 9 numbers. In an
N-dimensional space, scalars will still require only one number, while vectors will require N
numbers, and tensors will require N^R numbers. This explains why you often hear that
scalars are tensors of rank 0: since they have no direction, you can represent them with one
number.

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 5/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

With this in mind, it’s relatively easy to recognize scalars, vectors, and tensors and to set
them apart: scalars can be represented by a single number, vectors by an ordered set of
numbers, and tensors by an array of numbers.

What makes tensors so unique is the combination of components and basis vectors: basis
vectors transform one way between reference frames and the components transform in just
such a way as to keep the combination between components and basis vectors the same.

Installing TensorFlow
Now that you know more about TensorFlow, it’s time to get started and install the library.
Here, it’s good to know that TensorFlow provides APIs for Python, C++, Haskell, Java, Go,
Rust, and there’s also a third-party package for R called tensorflow .

Tip: if you want to know more about deep learning packages in R, consider checking out
DataCamp’s keras: Deep Learning in R Tutorial.

In this tutorial, you will download a version of TensorFlow that will enable you to write the
code for your deep learning project in Python. On the TensorFlow installation webpage, you’ll
see some of the most common ways and latest instructions to install TensorFlow using
virtualenv , pip , Docker and lastly, there are also some of the other ways of installing
TensorFlow on your personal computer.

Note You can also install TensorFlow with Conda if you’re working on Windows. However,
since the installation of TensorFlow is community supported, it’s best to check the of cial
installation instructions.

Now that you have gone through the installation process, it’s time to double check that you
have installed TensorFlow correctly by importing it into your workspace under the alias tf :

import tensorflow as tf

Note that the alias that you used in the line of code above is sort of a convention - It’s used
to ensure that you remain consistent with other developers that are using TensorFlow in
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 6/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

data science projects on the one hand, and with open-source TensorFlow projects on the
other hand.

Getting Started With TensorFlow: Basics


You’ll generally write TensorFlow programs, which you run as a chunk; This is at rst sight
kind of contradictory when you’re working with Python. However, if you would like, you can
also use TensorFlow’s Interactive Session, which you can use to work more interactively with
the library. This is especially handy when you’re used to working with IPython.

For this tutorial, you’ll focus on the second option: this will help you to get kickstarted with
deep learning in TensorFlow. But before you go any further into this, let’s rst try out some
minor stuff before you start with the heavy lifting.

First, import the tensorflow library under the alias tf , as you have seen in the previous
section. Then initialize two variables that are actually constants. Pass an array of four
numbers to the constant() function.

Note that you could potentially also pass in an integer, but that more often than not, you’ll
nd yourself working with arrays. As you saw in the introduction, tensors are all about
arrays! So make sure that you pass in an array :) Next, you can use multiply() to multiply
your two variables. Store the result in the result variable. Lastly, print out the result
with the help of the print() function.

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 7/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Note that you have de ned constants in the DataCamp Light code chunk above. However,
there are two other types of values that you can potentially use, namely placeholders, which
are values that are unassigned and that will be initialized by the session when you run it. Like
the name already gave away, it’s just a placeholder for a tensor that will always be fed when
the session is run; There are also Variables, which are values that can change. The constants,
as you might have already gathered, are values that don’t change.

The result of the lines of code is an abstract tensor in the computation graph. However,
contrary to what you might expect, the result doesn’t actually get calculated. It just
de ned the model, but no process ran to calculate the result. You can see this in the print-
out: there’s not really a result that you want to see (namely, 30). This means that TensorFlow
has a lazy evaluation!

However, if you do want to see the result, you have to run this code in an interactive session.
You can do this in a few ways, as is demonstrated in the DataCamp Light code chunks below:

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 8/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Note that you can also use the following lines of code to start up an interactive Session, run
the result and close the Session automatically again after printing the output :

In the code chunks above you have just de ned a default Session, but it’s also good to know
that you can pass in options as well. You can, for example, specify the config argument and
then use the ConfigProto protocol buffer to add con guration options for your session.

For example, if you add

config=tf.ConfigProto(log_device_placement=True)

to your Session, you make sure that you log the GPU or CPU device that is assigned to an
operation. You will then get information which devices are used in the session for each
operation. You could use the following con guration session also, for example, when you use
soft constraints for the device placement:

config=tf.ConfigProto(allow_soft_placement=True)
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 9/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Now that you’ve got TensorFlow installed and imported into your workspace and you’ve gone
through the basics of working with this package, it’s time to leave this aside for a moment
and turn your attention to your data. Just like always, you’ll rst take your time to explore
and understand your data better before you start modeling your neural network.

Belgian Traffic Signs: Background


Even though traf c is a topic that is generally known amongst you all, it doesn’t hurt going
brie y over the observations that are included in this dataset to see if you understand
everything before you start. In essence, in this section, you’ll get up to speed with the
domain knowledge that you need to have to go further with this tutorial.

Of course, because I’m Belgian, I’ll make sure you’ll also get some anecdotes :)

Belgian traf c signs are usually in Dutch and French. This is good to know, but for the
dataset that you’ll be working with, it’s not too important!

There are six categories of traf c signs in Belgium: warning signs, priority signs,
prohibitory signs, mandatory signs, signs related to parking and standing still on the road
and, lastly, designatory signs.

On January 1st, 2017, more than 30,000 traf c signs were removed from Belgian roads.
These were all prohibitory signs relating to speed.

Talking about removal, the overwhelming presence of traf c signs has been an ongoing
discussion in Belgium (and by extension, the entire European Union).

Loading And Exploring The Data


Now that you have gathered some more background information, it’s time to download the
dataset here. You should get the two zip les listed next to "BelgiumTS for Classi cation
(cropped images), which are called "BelgiumTSC_Training" and "BelgiumTSC_Testing".
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 10/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Tip: if you have downloaded the les or will do so after completing this tutorial, take a look at
the folder structure of the data that you’ve downloaded! You’ll see that the testing, as well as
the training data folders, contain 61 subfolders, which are the 62 types of traf c signs that
you’ll use for classi cation in this tutorial. Additionally, you’ll nd that the les have the le
extension .ppm or Portable Pixmap Format. You have downloaded images of the traf c
signs!

Let’s get started with importing the data into your workspace. Let’s start with the lines of
code that appear below the User-De ned Function (UDF) load_data() :

First, set your ROOT_PATH . This path is the one where you have made the directory with
your training and test data.

Next, you can add the speci c paths to your ROOT_PATH with the help of the join()
function. You store these two speci c paths in train_data_directory and
test_data_directory .

You see that after, you can call the load_data() function and pass in the
train_data_directory to it.

Now, the load_data() function itself starts off by gathering all the subdirectories that are
present in the train_data_directory ; It does so with the help of list comprehension,
which is quite a natural way of constructing lists - it basically says that, if you nd
something in the train_data_directory , you’ll double check whether this is a directory,
and if it is one, you’ll add it to your list. Remember that each subdirectory represents a
label.

Next, you have to loop through the subdirectories. You rst initialize two lists, labels
and images . Next, you gather the paths of the subdirectories and the le names of the
images that are stored in these subdirectories. After, you can collect the data in the two
lists with the help of the append() function.

def load_data(data_directory):
directories = [d for d in os.listdir(data_directory)

Want to leave aifcomment?


os.path.isdir(os.path.join(data_directory, d))]
labels = []
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 11/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

images = []
for d in directories:
label_directory = os.path.join(data_directory, d)
file_names = [os.path.join(label_directory, f)
for f in os.listdir(label_directory)
if f.endswith(".ppm")]
for f in file_names:
images.append(skimage.data.imread(f))
labels.append(int(d))
return images, labels

ROOT_PATH = "/your/root/path"
train_data_directory = os.path.join(ROOT_PATH, "TrafficSigns/Training")
test_data_directory = os.path.join(ROOT_PATH, "TrafficSigns/Testing")

images, labels = load_data(train_data_directory)

Note that in the above code chunk, the training and test data are located in folders named
"Training" and "Testing", which are both subdirectories of another directory "Traf cSigns".
On a local machine, this could look something like "/Users/Name/Downloads/Traf cSigns",
with then two subfolders called "Training" and "Testing".

Tip: review how to write functions in Python with DataCamp's Python Functions Tutorial.

Traf c Sign Statistics

With your data loaded in, it’s time for some data inspection! You can start with a pretty
simple analysis with the help of the ndim and size attributes of the images array:

Note that the images and labels variables are lists, so you might need to use np.array()
to convert the variables to an array in your own workspace. This has been done for you here!

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 12/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Note that the images[0] that you printed out is, in fact, one single image that is
represented by arrays in arrays! This might seem counterintuitive at rst, but it’s something
that you’ll get used to as you go further into working with images in machine learning or
deep learning applications.

Next, you can also take a small look at the labels , but you shouldn’t see too many surprises
at this point:

These numbers already give you some insights into how successful your import was and the
exact size of your data. At rst sight, everything has been executed the way you expected it
to, and you see that the size of the array is considerable if you take into account that you’re
dealing with arrays within arrays.

Tip try adding the following attributes to your arrays to get more information about the
Want to leave a comment?
memory layout, the length of one array element in bytes and the total consumed bytes by

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 13/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

the array’s elements with the flags , itemsize , and nbytes attributes. You can test this
out in the IPython console in the DataCamp Light chunk above!

Next, you can also take a look at the distribution of the traf c signs:

Awesome job! Now let’s take a closer look at the histogram that you made!

You clearly see that not all types of traf c signs are equally represented in the dataset. This is
something that you’ll deal with later when you’re manipulating the data before you start
modeling your neural network.
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 14/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

At rst sight, you see that there are labels that are more heavily present in the dataset than
others: the labels 22, 32, 38, and 61 de nitely jump out. At this point, it’s nice to keep this in
mind, but you’ll de nitely go further into this in the next section!

Visualizing The Traf c Signs

The previous, small analyses or checks have already given you some idea of the data that
you’re working with, but when your data mostly consists of images, the step that you should
take to explore your data is by visualizing it.

Let’s check out some random traf c signs:

First, make sure that you import the pyplot module of the matplotlib package under
the common alias plt .

Then, you’re going to make a list with 4 random numbers. These will be used to select
traf c signs from the images array that you have just inspected in the previous section. In
this case, you go for 300 , 2250 , 3650 and 4000 .

Next, you’ll say that for every element in the length of that list, so from 0 to 4, you’re going
to create subplots without axes (so that they don’t go running with all the attention and
your focus is solely on the images!). In these subplots, you’re going to show a speci c
image from the images array that is in accordance with the number at the index i . In
the rst loop, you’ll pass 300 to images[] , in the second round 2250 , and so on. Lastly,
you’ll adjust the subplots so that there’s enough width in between them.

The last thing that remains is to show your plot with the help of the show() function!

There you go:

# Import the `pyplot` module of `matplotlib`


import matplotlib.pyplot as plt

# Determine the (random) indexes of the images that you want to see
traffic_signs = [300, 2250, 3650, 4000]

Want to leave a comment?


# Fill out the subplots with the random images that you defined
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 15/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

for i in range(len(traffic_signs)):
plt.subplot(1, 4, i+1)
plt.axis('off')
plt.imshow(images[traffic_signs[i]])
plt.subplots_adjust(wspace=0.5)

plt.show()

As you guessed by the 62 labels that are included in this dataset, the signs are different from
each other.

But what else do you notice? Take another close look at the images below:

These four images are not of the same size!

You can obviously toy around with the numbers that are contained in the traffic_signs
list and follow up more thoroughly on this observation, but be as it may, this is an important
observation which you will need to take into account when you start working more towards
manipulating your data so that you can feed it to the neural network.

Let’s con rm the hypothesis of the differing sizes by printing the shape, the minimum and
maximum values of the speci c images that you have included into the subplots.

The code below heavily resembles the one that you used to create the above plot, but differs
in the fact that here, you’ll alternate sizes and images instead of plotting just the images next
to each other:
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 16/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

# Import `matplotlib`
import matplotlib.pyplot as plt

# Determine the (random) indexes of the images


traffic_signs = [300, 2250, 3650, 4000]

# Fill out the subplots with the random images and add shape, min and max values
for i in range(len(traffic_signs)):
plt.subplot(1, 4, i+1)
plt.axis('off')
plt.imshow(images[traffic_signs[i]])
plt.subplots_adjust(wspace=0.5)
plt.show()
print("shape: {0}, min: {1}, max: {2}".format(images[traffic_signs[i]].shape,
images[traffic_signs[i]].min(),
images[traffic_signs[i]].max()))

Note how you use the format() method on the string


"shape: {0}, min: {1}, max: {2}" to ll out the arguments {0} , {1} , and {2} that
you de ned.

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 17/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Now that you have seen loose images, you might also want to revisit the histogram that you
printed out in the rst steps of your data exploration; You can easily do this by plotting an
overview of all the 62 classes and one image that belongs to each class:

# Import the `pyplot` module as `plt`


import matplotlib.pyplot as plt

# Get the unique labels


unique_labels = set(labels)
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 18/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

# Initialize the figure


plt.figure(figsize=(15, 15))

# Set a counter
i = 1

# For each unique label,


for label in unique_labels:
# You pick the first image for each label
image = images[labels.index(label)]
# Define 64 subplots
plt.subplot(8, 8, i)
# Don't include axes
plt.axis('off')
# Add a title to each subplot
plt.title("Label {0} ({1})".format(label, labels.count(label)))
# Add 1 to the counter
i += 1
# And you plot this first image
plt.imshow(image)

# Show the plot


plt.show()

Note that even though you de ne 64 subplots, not all of them will show images (as there are
only 62 labels!). Note also that again, you don’t include any axes to make sure that the
readers’ attention doesn’t dwell far from the main topic: the traf c signs!

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 19/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

As you mostly guessed in the histogram above, there are considerably more traf c signs with
labels 22, 32, 38, and 61. This hypothesis is now con rmed in this plot: you see that there are
375 instances with label 22, 316 instances with label 32, 285 instances with label 38 and,
lastly, 282 instances with label 61.

One of the most interesting questions that you could ask yourself now is whether there’s a
connection between all of these instances - maybe all of them are designatory signs?

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 20/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Let’s take a closer look: you see that label 22 and 32 are prohibitory signs, but that labels 38
and 61 are designatory and a prioritory signs, respectively. This means that there’s not an
immediate connection between these four, except for the fact that half of the signs that have
a substantial presence in the dataset is of the prohibitory kind.

Feature Extraction
Now that you have thoroughly explored your data, it’s time to get your hands dirty! Let’s
recap brie y what you discovered to make sure that you don’t forget any steps in the
manipulation:

The size of the images was unequal;

There are 62 labels or target values (as your labels start at 0 and end at 61);

The distribution of the traf c sign values is pretty unequal; There wasn’t really any
connection between the signs that were heavily present in the dataset.

Now that you have a clear idea of what you need to improve, you can start with manipulating
your data in such a way that it’s ready to be fed to the neural network or whichever model
you want to feed it too. Let’s start rst with extracting some features - you’ll rescale the
images, and you’ll convert the images that are held in the images array to grayscale. You’ll
do this color conversion mainly because the color matters less in classi cation questions like
the one you’re trying to answer now. For detection, however, the color does play a big part!
So in those cases, it’s not needed to do that conversion!

Rescaling Images

To tackle the differing image sizes, you’re going to rescale the images; You can easily do this
with the help of the skimage or Scikit-Image library, which is a collection of algorithms for
image processing.

In this case, the transform module will come in handy, as it offers you a resize()
function; You’ll see that you make use of list comprehension (again!) to resize each image to
28 by 28Want
pixels. Once again, you see that the way you actually form the list: for every image
to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 21/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

that you nd in the images array, you’ll perform the transformation operation that you
borrow from the skimage library. Finally, you store the result in the images28 variable:

# Import the `transform` module from `skimage`


from skimage import transform

# Rescale the images in the `images` array


images28 = [transform.resize(image, (28, 28)) for image in images]

This was fairly easy wasn’t it?

Note that the images are now four-dimensional: if you convert images28 to an array and if
you concatenate the attribute shape to it, you’ll see that the printout tells you that
images28 ’s dimensions are (4575, 28, 28, 3) . The images are 784-dimensional (because
your images are 28 by 28 pixels).

You can check the result of the rescaling operation by re-using the code that you used above
to plot the 4 random images with the help of the traffic_signs variable. Just don’t forget
to change all references to images to images28 .

Check out the result here:

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 22/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Note that because you rescaled, your min and max values have also changed; They seem to
be all in the same ranges now, which is really great because then you don’t necessarily need
to normalize your data!

Image Conversion to Grayscale

As said in the introduction to this section of the tutorial, the color in the pictures matters
less when you’re trying to answer a classi cation question. That’s why you’ll also go through
the trouble of converting the images to grayscale.

Note, however, that you can also test out on your own what would happen to the nal results
of your model if you don’t follow through with this speci c step.

Just like with the rescaling, you can again count on the Scikit-Image library to help you out;
In this case,
Wantit’s the color
to leave module with its rgb2gray() function that you need to use to get
a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 23/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

where you need to be.

That’s going to be nice and easy!

However, don’t forget to convert the images28 variable back to an array, as the rgb2gray()
function does expect an array as an argument.

# Import `rgb2gray` from `skimage.color`


from skimage.color import rgb2gray

# Convert `images28` to an array


images28 = np.array(images28)

# Convert `images28` to grayscale


images28 = rgb2gray(images28)

Double check the result of your grayscale conversion by plotting some of the images; Here,
you can again re-use and slightly adapt some of the code to show the adjusted images:

import matplotlib.pyplot as plt

traffic_signs = [300, 2250, 3650, 4000]

for i in range(len(traffic_signs)):
plt.subplot(1, 4, i+1)
plt.axis('off')
plt.imshow(images28[traffic_signs[i]], cmap="gray")
plt.subplots_adjust(wspace=0.5)

# Show the plot


plt.show()

Note that you indeed have to specify the color map or cmap and set it to "gray" to plot the
images in grayscale. That is because imshow() by default uses, by default, a heatmap-like
color map. Read more here.
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 24/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Tip: since you have been re-using this function quite a bit in this tutorial, you might look into
how you can make it into a function :)

These two steps are very basic ones; Other operations that you could have tried out on your
data include data augmentation (rotating, blurring, shifting, changing brightness,…). If you
want, you could also set up an entire pipeline of data manipulation operations through which
you send your images.

Deep Learning With TensorFlow


Now that you have explored and manipulated your data, it’s time to construct your neural
network architecture with the help of the TensorFlow package!

Modeling The Neural Network

Just like you might have done with Keras, it’s time to build up your neural network, layer by
layer.

If you haven’t done so already, import tensorflow into your workspace under the
conventional alias tf . Then, you can initialize the Graph with the help of Graph() . You use
this function to de ne the computation. Note that with the Graph, you don’t compute
anything, because it doesn’t hold any values. It just de nes the operations that you want to
be running later.

In this case, you set up a default context with the help of as_default() , which returns a
context manager that makes this speci c Graph the default graph. You use this method if
you want to create multiple graphs in the same process: with this function, you have a global
default graph to which all operations will be added if you don’t explicitly create a new graph.

Next, you’re ready to add operations to your graph. As you might remember from working
Want
with Keras, to leave
you buildaup
comment?
your model, and then in compiling it, you de ne a loss function, an

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 25/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

optimizer, and a metric. This now all happens in one step when you work with TensorFlow:

First, you de ne placeholders for inputs and labels because you won’t put in the “real” data
yet. Remember that placeholders are values that are unassigned and that will be initialized
by the session when you run it. So when you nally run the session, these placeholders will
get the values of your dataset that you pass in the run() function!

Then, you build up the network. You rst start by attening the input with the help of the
flatten() function, which will give you an array of shape [None, 784] instead of the
[None, 28, 28] , which is the shape of your grayscale images.

After you have attened the input, you construct a fully connected layer that generates
logits of size [None, 62] . Logits is the function operates on the unscaled output of
previous layers, and that uses the relative scale to understand the units is linear.

With the multi-layer perceptron built out, you can de ne the loss function. The choice for
a loss function depends on the task that you have at hand: in this case, you make use of

sparse_softmax_cross_entropy_with_logits()

This computes sparse softmax cross entropy between logits and labels. In other words, it
measures the probability error in discrete classi cation tasks in which the classes are
mutually exclusive. This means that each entry is in exactly one class. Here, a traf c sign
can only have one single label. Remember that, while regression is used to predict
continuous values, classi cation is used to predict discrete values or classes of data points.
You wrap this function with reduce_mean() , which computes the mean of elements
across dimensions of a tensor.

You also want to de ne a training optimizer; Some of the most popular optimization
algorithms used are the Stochastic Gradient Descent (SGD), ADAM and RMSprop.
Depending on whichever algorithm you choose, you’ll need to tune certain parameters,
such as learning rate or momentum. In this case, you pick the ADAM optimizer, for which
you de ne the learning rate at 0.001 .

Lastly, you initialize the operations to execute before going over to the training.

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 26/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

# Import `tensorflow`
import tensorflow as tf

# Initialize placeholders
x = tf.placeholder(dtype = tf.float32, shape = [None, 28, 28])
y = tf.placeholder(dtype = tf.int32, shape = [None])

# Flatten the input data


images_flat = tf.contrib.layers.flatten(x)

# Fully connected layer


logits = tf.contrib.layers.fully_connected(images_flat, 62, tf.nn.relu)

# Define a loss function


loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels = y,
logits = logits))
# Define an optimizer
train_op = tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)

# Convert logits to label indexes


correct_pred = tf.argmax(logits, 1)

# Define an accuracy metric


accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))

You have now successfully created your rst neural network with TensorFlow!

If you want, you can also print out the values of (most of) the variables to get a quick recap or
checkup of what you have just coded up:

print("images_flat: ", images_flat)


print("logits: ", logits)
print("loss: ", loss)
print("predicted_labels: ", correct_pred)

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 27/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Tip: if you see an error like “ module 'pandas' has no attribute 'computation' ”,
consider upgrading the packages dask by running pip install --upgrade dask in your
command line. See this StackOver ow post for more information.

Running The Neural Network

Now that you have built up your model layer by layer, it’s time to actually run it! To do this,
you rst need to initialize a session with the help of Session() to which you can pass your
graph that you de ned in the previous section. Next, you can run the session with run() ,
to which you pass the initialized operations in the form of the init variable that you also
de ned in the previous section.

Next, you can use this initialized session to start epochs or training loops. In this case, you
pick 201 because you want to be able to register the last loss_value ; In the loop, you run
the session with the training optimizer and the loss (or accuracy) metric that you de ned in
the previous section. You also pass a feed_dict argument, with which you feed data to the
model. After every 10 epochs, you’ll get a log that gives you more insights into the loss or
cost of the model.

As you have seen in the section on the TensorFlow basics, there is no need to close the
session manually; this is done for you. However, if you want to try out a different setup, you
probably will need to do so with sess.close() if you have de ned your session as sess ,
like in the code chunk below:

tf.set_random_seed(1234)
sess = tf.Session()

sess.run(tf.global_variables_initializer())

for i in range(201):
print('EPOCH', i)
_, accuracy_val = sess.run([train_op, accuracy], feed_dict={x: images28, y: labels})
if i % 10 == 0:
print("Loss: ", loss)
print('DONE WITH EPOCH')

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 28/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Remember that you can also run the following piece of code, but that one will immediately
close the session afterward, just like you saw in the introduction of this tutorial:

tf.set_random_seed(1234)

with tf.Session() as sess:


sess.run(tf.global_variables_initializer())
for i in range(201):
_, loss_value = sess.run([train_op, loss], feed_dict={x: images28, y: labels})
if i % 10 == 0:
print("Loss: ", loss)

Note that you make use of global_variables_initializer() because the


initialize_all_variables() function is deprecated.

You have now successfully trained your model! That wasn’t too hard, was it?

Evaluating Your Neural Network

You’re not entirely there yet; You still need to evaluate your neural network. In this case, you
can already try to get a glimpse of well your model performs by picking 10 random images
and by comparing the predicted labels with the real labels.

You can rst print them out, but why not use matplotlib to plot the traf c signs
themselves and make a visual comparison?

# Import `matplotlib`
import matplotlib.pyplot as plt
import random

# Pick 10 random images


sample_indexes = random.sample(range(len(images28)), 10)
sample_images = [images28[i] for i in sample_indexes]
sample_labels = [labels[i] for i in sample_indexes]

# Run the "correct_pred" operation


Want to leave a comment?
predicted = sess.run([correct_pred], feed_dict={x: sample_images})[0]

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 29/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

# Print the real and predicted labels


print(sample_labels)
print(predicted)

# Display the predictions and the ground truth visually.


fig = plt.figure(figsize=(10, 10))
for i in range(len(sample_images)):
truth = sample_labels[i]
prediction = predicted[i]
plt.subplot(5, 2,1+i)
plt.axis('off')
color='green' if truth == prediction else 'red'
plt.text(40, 10, "Truth: {0}\nPrediction: {1}".format(truth, prediction),
fontsize=12, color=color)
plt.imshow(sample_images[i], cmap="gray")

plt.show()

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 30/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

However, only looking at random images don’t give you many insights into how well your
model actually performs. That’s why you’ll load in the test data.

Note that you make use of the load_data() function, which you de ned at the start of this
tutorial.

# Import `skimage`
from skimage import transform

# Load the test data


test_images, test_labels = load_data(test_data_directory)

Want tothe
# Transform leave a comment?
images to 28 by 28 pixels

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 31/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

test_images28 = [transform.resize(image, (28, 28)) for image in test_images]

# Convert to grayscale
from skimage.color import rgb2gray
test_images28 = rgb2gray(np.array(test_images28))

# Run predictions against the full test set.


predicted = sess.run([correct_pred], feed_dict={x: test_images28})[0]

# Calculate correct matches


match_count = sum([int(y == y_) for y, y_ in zip(test_labels, predicted)])

# Calculate the accuracy


accuracy = match_count / len(test_labels)

# Print the accuracy


print("Accuracy: {:.3f}".format(accuracy))

Remember to close off the session with sess.close() in case you didn't use the
with tf.Session() as sess: to start your TensorFlow session.

Where To Go Next?
If you want to continue working with this dataset and the model that you have put together
in this tutorial, try out the following things:

Apply regularized LDA on the data before you feed it to your model. This is a suggestion
that comes from one of the original papers, written by the researchers that gathered and
analyzed this dataset.

You could also, as said in the tutorial itself, also look at some other data augmentation
operations that you can perform on the traf c sign images. Additionally, you could also try
to tweak this network further; The one that you have created now was fairly simple.

Early stopping: Keep track of the training and testing error while you train the neural
network. Stop training when both errors go down and then suddenly go back up - this is a
Want to leave a comment?
sign that the neural network has started to over t the training data.

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 32/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Play around with the optimizers.

Make sure to check out the Machine Learning With TensorFlow book, written by Nishant
Shukla.

Tip also check out the TensorFlow Playground and the TensorBoard.

If you want to keep on working with images, de nitely check out DataCamp’s scikit-learn
tutorial, which tackles the MNIST dataset with the help of PCA, K-Means and Support Vector
Machines (SVMs). Or take a look at other tutorials such as this one that uses the Belgian
traf c signs dataset.

345 108

RELATED POSTS

MUST READ PYTHON +1

Python Machine Learning: Scikit-Learn Tutorial

Karlijn Willems
February 25th, 2019

MUST READ PYTHON +4

Keras Tutorial: Deep Learning in Python

Want Willems
Karlijn to leave a comment?
February 4th, 2019

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 33/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

MUST READ MACHINE LEARNING +4

Detecting Fake News with Scikit-Learn

Katharine Jarmul
August 24th, 2017

COMMENTS

Mofakharul Islam
19/02/2018 03:55 PM

Having a bit of trouble, perhaps my understanding isn't quite there. While I attempted to import
Belgian Traf c Signs datasets into my tensor ow workspace getting the following error message;

...: ROOT_PATH = "C:\Users\Mofakharul\Documents\DeepLearningLiteratures"

train_data_directory = os.path.join(ROOT_PATH, "Traf cSigns/Training")

test_data_directory = os.path.join(ROOT_PATH, "Traf cSigns/Testing")

images, labels = load_data(train_data_directory)

  File "<ipython-input-15-44b277681a5a>", line 17

    ROOT_PATH = "C:\Users\Mofakharul\Documents\DeepLearningLiteratures"

               ^

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated
\UXXXXXXXX escape

IWant
simplytocopied
leave athe
comment?
following code (your code) with replacing "/your/root/path" with my one
"C:\Users\Mofakharul\Documents\DeepLearningLiteratures";
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 34/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

def load_data(data_directory):

    directories = [d for d in os.listdir(data_directory) 

                   if os.path.isdir(os.path.join(data_directory, d))]

    labels = []

    images = []

    for d in directories:

        label_directory = os.path.join(data_directory, d)

         le_names = [os.path.join(label_directory, f) 

                      for f in os.listdir(label_directory) 

                      if f.endswith(".ppm")]

        for f in le_names:

            images.append(skimage.data.imread(f))

            labels.append(int(d))

    return images, labels

ROOT_PATH = "/your/root/path"

train_data_directory = os.path.join(ROOT_PATH, "Traf cSigns/Training")

test_data_directory = os.path.join(ROOT_PATH, "Traf cSigns/Testing")

images, labels = load_data(train_data_directory)

I am unable to gure out what went wrong. Your help and assistance in this regards would be
much appreciated. 

Want to leave a comment?


5 R E P LY

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 35/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Karlijn Willems
19/02/2018 04:35 PM

Hi moislam522000 - Maybe this StackOver ow thread could be of some help. Otherwise


de nitely take a look at the Jupyter Notebook that is complementary to this tutorial.

4 R E P LY

Mofakharul Islam
20/02/2018 01:49 PM

Thank you so much .

Benjamin Edelstein
10/09/2018 09:09 PM

Is there a tutorial for the universal sentence encoder? 

Akina Yap
09/04/2018 03:03 PM

I think the problem is that you need to use


 "C:\\Users\\Mofakharul\\Documents\\DeepLearningLiteratures" instead because of the
slashes which is an escape character.  https://en.wikipedia.org/wiki/Escape_character -> this
would cause some weird errors due to the fact that it should not be used, so you should
"escape" the escape character for it to work

0 R E P LY

Thaddeus (Thad) Gabara


07/09/2018 11:59 PM

too bad you do not explain  what the following does:

 Where is the source, where is the destination?

ROOT_PATH = "/Users/karlijnwillems/Downloads/"
train_data_dir = os.path.join(ROOT_PATH, "TrafficSigns/Training")
test_data_dir = os.path.join(ROOT_PATH, "TrafficSigns/Testing")

1 R E P LY

Yao Boxu
11/10/2018 06:35 AM

Fist you should  make a directory named Traf cSigns in ROOT_PATH


Want to leave a comment?
and then unzip the dataset to  Traf cSigns.
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 36/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

like this    

/Users/karlijnwillems/Downloads/TrafficSigns/Training

/Users/karlijnwillems/Downloads/TrafficSigns/Testing

Oskar Paulsson
15/06/2019 03:56 PM

I'm having issues with this exact piece of code - albeit not the same issue as above - I get
NameError: name 'os' is not de ned

Edit: I found out I needed to import os and then also install and import skimage. It seems to
work now!

Андрей Таранов
03/02/2019 09:22 PM

Hi, well done, thanks a lot. Why didn't you tell how to save/restore the model?

2 R E P LY

zimborodger
21/02/2018 05:02 PM

Hi.

Could you please share the source code of your tutorial on github

1 R E P LY

Karlijn Willems
21/02/2018 08:22 PM

Hi zimborodger - You can nd the notebook here. I'll make sure to adjust the link in this post
Want
soon!
to :)leave
Thanks
a comment?
for letting me know! 

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 37/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

3 R E P LY

zimborodger
26/02/2018 04:32 PM

Thank you very much! I appreciate your hard work 

Eirik Lid
28/02/2018 07:05 PM

Hi,

i get a wrong shape from 

images28 = rgb2gray(images28)

The shape is:

(4575, 28, 3)

Before running rgb2gray() the shape is (4575, 28, 28, 3)

Is there a way to x this?

2 R E P LY

Karlijn Willems
28/02/2018 07:30 PM

Hi eiriklid - Did something maybe go wrong when you resized the images?  I'd recommend you
to take a look at the notebook if you haven't already!

1 R E P LY

Eirik Lid
05/03/2018 06:57 PM

Seems I needed to update scikit-image...

Radu Paul Mondescu


02/03/2018 12:03 AM

The skimage.data,imread
Want - cannot nd in any package - I guess we need scikit-image ? but what
to leave a comment?
version ? 
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 38/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

2 R E P LY

Karlijn Willems
02/03/2018 01:13 AM

Hi Radu Paul Mondescu - The required package version is skimage 0.12.3. You can nd more in
the notebook that is linked at the start of this tutorial :) 

1 R E P LY

Radu Paul Mondescu


05/03/2018 07:58 PM

Hi Karlijn - thanks want to go myself thru the code - no copy and paste :-) ... thanks after a
bit of digging everything works! Nice exposure! radu

Radu Paul Mondescu


02/03/2018 01:12 AM

you are transforming labels between np.array and list - I think is a bit confusing

2 R E P LY

Anu V Vivin
16/03/2018 11:09 AM

For asp.net check below url will help

http://tensor owapi.blogspot.in/2018/03/integrating-tensor- ow-api-into-aspnet.html

1 R E P LY

M NF
20/03/2018 10:05 PM

I am new to this eld . will this classi er works for other object(any word or character) ?    

2 R E P LY

Reinaldo Cevallos
28/03/2018 10:15 PM

I am new to neural networks and trying to conceptualize this code. There is no hidden layer here
right? 
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 39/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

The network just ows from the attened images, to the output of the
"tf.contrib.layers.fully_connected" output? I guess we use the argmax function to convert that
output back to labels but that's not a layer.

4 R E P LY

Ti m
05/12/2018 08:28 PM

I think you're right! Had the same impression, when going through the tutorial.

1 R E P LY

milicakovjanic89
03/04/2018 03:41 AM

Hi.

Great tutorial! But can I use this code on my own dataset of images that are jpg. format? Do I need
to convert them into .ppm format?  

1 R E P LY

Ariyo Apakama
03/04/2018 08:57 PM

insightful

3 R E P LY

brostami
13/04/2018 12:10 AM

I am new to tensor ow. I tried the code but I got the error "unde ned name skimage". I think I
should install that package? am I right? But I could not nd how to download the package! would
you please provide some hint? Also, I read some parts of the notebook is linked at the start of the
tutorial. Thank you. 

1 R E P LY

Karlijn Willems
13/04/2018 03:05 PM

Hi Brostami - Maybe this link can help you out?

1 R E P LY

himansu
Want to odedra
leave a comment?
24/04/2018 01:50 AM

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 40/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Hi, was wondering if you could help me with the following. Just trying to load the data into python
(i'm using anaconda) and everything goes well however I have noticed that my images list only
contains 15 les. This is really odd my code is somewhat identical to yours as well. Please help
thank you 

1 R E P LY

himansu odedra
24/04/2018 03:45 PM

solved!

1 R E P LY

Bruno Gonçalves
25/04/2018 01:03 AM

Hello, in the last part when I try to run the test set , it returns the following error:  

the input array must be have a shape == (.., ..,[ ..,] 3)), got (0)

And it points to

test_images28 = rgb2gray(np.array(test_images28))

Any help would be nice, thank u :) 

1 R E P LY

Bruno Gonçalves
25/04/2018 05:03 PM

Problem solved

2 R E P LY

Jae Duk Seo


10/05/2018 03:48 AM

Great tutorial!

1 R E P LY
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 41/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Björn Lindqvist
11/05/2018 06:18 PM

One line of one code sample should be changed from print("Loss: ", loss) to print("Loss: ",
loss_value)

2 R E P LY

long xie
16/05/2018 09:26 AM

非常棒的入门教程,谢谢楼主分享👍

1 R E P LY

Marias Mo
31/05/2018 02:48 AM

Hi Karlijn,

Great article. Question. So you mentioned graph. But I dont see you using the tf.Graph() anywhere
in your code. Is that optional??

Thanks

6 R E P LY

S Rao
31/05/2018 11:09 AM

Thought it was a free tutorial.

1 R E P LY

Nickolai Hazen
01/06/2018 08:53 PM

I don't quite understand how np.array() is supposed to function. I can use the LoadData function
ne, but when I run the next code snippet in IDLE, I get this error:

File "C:\Users\User\source\repos\N2-2\N2-2\N2_2.py", line 35, in <module>

    print(images.ndim)

AttributeError: 'list' object has no attribute 'ndim'


Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 42/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

I appreciate your help in advance.

3 R E P LY

Rajesh Patidar
06/10/2018 03:24 PM

have to put

import numpy as np;

and then convert the array

images = np.array(images)

3 R E P LY

Sourabh Kulkarni
03/06/2018 07:30 PM

Hi Karlijn,

Thanks for the great tutorial. I am new to Tensor ow. I tried the code, it is working absolutely ne.
But I have a doubt like how many hidden layers are involved here in training the model?

Thanks in advance!

2 R E P LY

Soumyadip Majumder
04/06/2018 05:43 PM

 logits = tf.contrib.layers.fully_connected(images_ at, 62, tf.nn.relu) 

What is the logic of calculating "62"? Can anyone explain this to me? I am completely new to this
eld.  Thanks in advance!

1 R E P LY

Gowtham R
01/07/2018 05:20 PM
Want to leave a comment?
I hope its the number of distinct labels

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 43/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

1 R E P LY

Yao Boxu
11/10/2018 06:30 AM

len(set(labels))=62,  it means the number of classes.

1 R E P LY

Valerio Rizzo
15/01/2019 10:12 PM

It is the number of categories of your dataset. That line of code will "connect" each of the 784
inputs obtained by attening the 28x28 array of each image pixel values, with your 62 possible
output. This can be an easy way to think at it.

1 R E P LY

Mohammad Shari
06/06/2018 03:54 PM

very helpful, thank you

1 R E P LY

Harshali Patel
11/06/2018 03:07 PM

Really nice and in depth article on Tensor ow. Tensors were explained in very detail. You can read
more on tensor ow applications for more clarity. 

1 R E P LY

Jon Mateo
20/06/2018 11:12 PM

Hi Karlijn, 

Thanks for the tutorial.

Im getting  'AttributeError: module 'skimage' has no attribute 'data''  - i have installed scikit-image
and scikit-learn (as recommended in the notebook), but still get the same issue. 

Would be great if you could give me some tips.

Thanks,

Jon
Want to leave a comment?
1 R E P LY
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 44/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Jon Mateo
21/06/2018 02:24 AM

If anyone else is struggling with the same issues, it seems that 'imread' is now housed in 'io'
rather than 'data'. 

You must import io by stating 'import io from skimage' at the top of your code!

Thanks,

Jon

1 R E P LY

Gowtham R
01/07/2018 05:26 PM

Great Tutorial. Thanks for taking us through tensor ow. I have a few doubts.

1. What are all the Loss Functions & Optimizing Algorithms. How to select one based on the task
(i.e.) where to use which ?

2. Graph Function - where to de ne it ?

3. How many layers are there in this ? can we increase or decrease the number of layers?

4. I am getting an error as "Not enough dimensions" while trying to plot the image using
"plt.imshow(image, cmap="gray")". This error occurs only when i use "images28 =
rgb2gray(images28)"

5. I tried using the same example, changed the images to my images and tried. I am getting
Memory Error. Any help is much Appreciated!!

Thanks again for a wonderful tutorial.

1 R E P LY

saroj kumar
05/07/2018 02:35 PM

 Great Tutorial. Thanks for taking us through tensor ow. I can write ablog like tensor ow
 interview questions 

Thanks ! 

Want
1 toRleave
E P LYa comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 45/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Vova Kuzmenkov
17/07/2018 10:22 PM

Hello Karlijn,

Great tutorial, thank you!

A question please: how do I print actual loss, when training the network. Current version prints
the tensor description rather than the loss:

DONE WITH EPOCH


EPOCH 189
DONE WITH EPOCH
EPOCH 190
Loss: Tensor("Mean:0", shape=(), dtype=float32)
DONE WITH EPOCH
EPOCH 191

Kindly advise,

Thank you!

1 R E P LY

Dirk Kinnaes
14/09/2018 03:37 PM

Hi Vova, you can do it like this:

_, accuracy_val, loss_val = sess.run([train_op, accuracy, loss], feed_dict={x: images28, y: labels})

print("Loss: ", loss_val)

1 R E P LY

Jaan Olev
23/07/2018 03:13 PM

Nice project. Thanks!

How can we make this model more accurate? 

- Do we have to add more images for training ? or train longer, better ? 


Want to leave a comment?
1 R E P LY
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 46/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Yao Boxu
11/10/2018 06:27 AM

wo can use cnn  not just fully connected

1 R E P LY

Андрей Таранов
03/02/2019 09:18 PM

seems to you r right, I passed through 10k epochs and get only 0.6 accuracy value. looks
sad.

Giri Annamalai
26/07/2018 06:41 PM

At "Loading And Exploring The Data", in the load_data() 

In python3, skimage.data.imread(f) shoudl be io.imread(f)


and "from skimage import io"

2 R E P LY

vinay TURPATI
06/08/2018 05:58 PM

colaboratory it was showing errors

1 R E P LY

ASEEM GOYAL
19/08/2018 01:27 PM

How did we reach the conclusion that `epochs` will be `201`?

3 R E P LY

KISHORE K
17/09/2018 07:02 PM

Very nice.Can you tell me how can we increase the accuracy by changing any parameters?

2 R E P LY

Want to leave
Szabó a comment?
András
18/09/2018 07:41 PM

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 47/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Hi, can you tell me please what accuracy you get? Because I get very bad, and I don't know
what I'm doing wrong..

Thanks

1 R E P LY

Yao Boxu
11/10/2018 06:26 AM

0.64

Dwight Foster
19/09/2018 04:08 AM

I am getting this error when I try to run my code

images.append(skimage.data.imread(f))

AttributeError: 'module' object has no attribute 'data'

import skimage

import tensor ow as tf

import os

v1 = tf.constant([2,3,5,6])

v2 = tf.constant([2,3,1,9])

result = tf.multiply(v1, v2)

with tf.Session() as sess:

    output = sess.run(result)

    con g = tf.Con gProto(log_device_placement = True)

    print(output)

    
Want to leave a comment?
sess.close()

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 48/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

def load_data(data_directory):

    directories = [d for d in os.listdir(data_directory) if os.path.isdir(os.path.join(data_directory,d))]

    labels = []

    images = []

    for d in directories:

        label_directory = os.path.join(data_directory, d)

         le_names = [os.path.join(label_directory, f) for f in os.listdir(label_directory) if


f.endswith(".ppm")]

        for f in le_names:

            images.append(skimage.data.imread(f))

            labels.append(int(d))

        return images, labels

    

    

ROOT_PATH = "/Users/Dwight/Downloads"

train_data_directory = os.path.join(ROOT_PATH, "Training")

test_data_directory = os.path.join(ROOT_PATH, "Testing")

images, labels = load_data(train_data_directory)

print(images.ndim)

        

can someone help me I am really confused

    

    

0 R E P LY

Yao Boxu
Want to leave
11/10/2018 a comment?
06:25 AM

from skimage import data


https://www.datacamp.com/community/tutorials/tensorflow-tutorial 49/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

images.append(data.imread(f))

1 R E P LY

Jiwoo Lee
10/10/2018 10:58 AM

Hi, thank you for the wonderful tutorial. I am very new to TF, and this tutorial helps me a lot to get
insight. One question I have is, following the tutorial, at the end I get Acurracy as 0.0, not sure if it
is supposed to be. Thank you.

1 R E P LY

Yao Boxu
11/10/2018 06:45 AM

Full Code partI:

import os
from skimage import data
import numpy as np
import matplotlib.pyplot as plt
from skimage import transform
from skimage.color import rgb2gray
import tensor ow as tf
import random

def load_data(data_directory):
   directories = [d for d in os.listdir(data_directory)
                  if os.path.isdir(os.path.join(data_directory, d))]
   labels = []
   images = []
   for d in directories:
       label_directory = os.path.join(data_directory, d)
        le_names = [os.path.join(label_directory, f)
                     for f in os.listdir(label_directory)
                     if f.endswith(".ppm")]
       for f in le_names:
           images.append(data.imread(f))
           labels.append(int(d))
Want toimages,
   return leave a labels
comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 50/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp
1 R E P LY

Yao Boxu
11/10/2018 06:49 AM

ROOT_PATH = "D:/dataset"

train_data_directory = os.path.join(ROOT_PATH, "Traf cSigns/Training")

test_data_directory = os.path.join(ROOT_PATH, "Traf cSigns/Testing")

images, labels = load_data(train_data_directory)

images = [transform.resize(image, (28, 28)) for image in images]

images = np.array(images)

images = rgb2gray(images)

plt.hist(labels, 62)

plt.show()

2 R E P LY

Yao Boxu
11/10/2018 06:52 AM

traf c_signs = [300, 2250, 3650, 4000]

for i in range(len(traf c_signs)):

    plt.subplot(1, 4, i+1)

    plt.axis('off')

    plt.imshow(images[traf c_signs[i]], cmap="gray")

    plt.subplots_adjust(wspace=0.5)  

plt.show()

plt. gure ( gsize=(15, 15))

i=1

unique_labels = set(labels)

for label in unique_labels:

    image = images[labels.index(label)]

Want    plt.subplot
to leave a comment?
(8, 8, i)

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 51/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

    plt.axis ('off')

    plt.title ("Label {0} ({1})".format(label, labels.count(label)))

    i += 1

    plt.imshow (image, cmap="gray")

plt.show ()

Yao Boxu
11/10/2018 06:53 AM

x = tf.placeholder(dtype = tf. oat32, shape=[None, 28, 28])

y = tf.placeholder(dtype = tf.int32, shape=[None])

images_ at = tf.contrib.layers. atten(x)

logits = tf.contrib.layers.fully_connected(images_ at, 62, tf.nn.relu)

loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y, logits=logits))

train_op = tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)

correct_pred = tf.argmax(logits, 1)

accuracy = tf.reduce_mean(tf.cast(correct_pred, tf. oat32))

sess = tf.Session()

sess.run(tf.global_variables_initializer())

1 R E P LY

Yao Boxu
11/10/2018 06:54 AM

for i in range(201):

        print('EPOCH', i)
Want to leave a comment?
        _, accuracy_val = sess.run([train_op, accuracy], feed_dict={x: images, y: labels})

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 52/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

        if i % 10 == 0:

            print("Loss: ", loss)

sample_indexes = random.sample (range(len(images)), 10)

sample_images = [images[i] for i in sample_indexes]

sample_labels = [labels[i] for i in sample_indexes]

predicted = sess.run ([correct_pred], feed_dict={x: sample_images})[0]

print (sample_labels)

print (predicted)

g = plt. gure( gsize=(10, 10))

for i in range (len (sample_images)):

    truth = sample_labels[i]

    prediction = predicted[i]

    plt.subplot (5, 2, 1 + i)

    plt.axis ('off')

    color = 'green' if truth == prediction else 'red'

    plt.text(40, 10, "Truth:  {0}\nPrediction: {1}".format(truth, prediction), fontsize=12, color=color)

    plt.imshow (sample_images[i], cmap="gray")

plt.show ()

1 R E P LY

Yao Boxu
11/10/2018 06:54 AM

for i in range(201):

        print('EPOCH', i)

        _, accuracy_val = sess.run([train_op, accuracy], feed_dict={x: images, y: labels})

        if i % 10 == 0:

            print("Loss: ", loss)


Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 53/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

sample_indexes = random.sample (range(len(images)), 10)

sample_images = [images[i] for i in sample_indexes]

sample_labels = [labels[i] for i in sample_indexes]

predicted = sess.run ([correct_pred], feed_dict={x: sample_images})[0]

print (sample_labels)

print (predicted)

g = plt. gure( gsize=(10, 10))

for i in range (len (sample_images)):

    truth = sample_labels[i]

    prediction = predicted[i]

    plt.subplot (5, 2, 1 + i)

    plt.axis ('off')

    color = 'green' if truth == prediction else 'red'

    plt.text(40, 10, "Truth:  {0}\nPrediction: {1}".format(truth, prediction), fontsize=12, color=color)

    plt.imshow (sample_images[i], cmap="gray")

plt.show ()

1 R E P LY

Yao Boxu
11/10/2018 06:55 AM

test_images, test_labels = load_data(test_data_directory)

test_images28 = [transform.resize(image, (28, 28)) for image in test_images]

test_images28 = rgb2gray(np.array(test_images28))

predicted = sess.run([correct_pred], feed_dict={x: test_images28})[0]

match_count = sum([int(y == y_) for y, y_ in zip(test_labels, predicted)])

accuracy = match_count / len(test_labels)

print("Accuracy: {:.3f}".format(accuracy))
Want to leave a comment?
1 R E P LY
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 54/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Ivan Sinarso
05/11/2018 08:28 PM

This is really help!


Awesome, thank you! :)

1 R E P LY

Onur Can Yücedağ


15/10/2018 06:46 PM

Karlijn, it is great tutorial thanks for sharing it.

1 R E P LY

Samer Choudhary
26/10/2018 12:14 PM

Where do we get the data set for use in this tuitorial

1 R E P LY

Ivan Sinarso
05/11/2018 07:59 PM

this one,, cheers!


https://raw.githubusercontent.com/datacamp/datacamp-community-
tutorials/master/TensorFlow%20Tutorial%20For%20Beginners/TensorFlow%20Tutorial%20F

1 R E P LY

Shila Liao
31/10/2018 09:13 PM

Hi 

I'm beginner

I stop in  skimage  import.

Can you teach me how to install  skimage  package correctly?

 After install "pip install -U scikit-image" 

"import skimage " in python is error

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 55/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Here is my error message:

Traceback (most recent call last):

  File ".\test.py", line 6, in <module>

    import skimage

  File "C:\Users\THU -27\AppData\Local\Programs\Python\Python36\lib\site-


packages\skimage\__init__.py", line 167, in <module>

    from .util.dtype import (img_as_ oat32,

  File "C:\Users\THU -27\AppData\Local\Programs\Python\Python36\lib\site-


packages\skimage\util\__init__.py", line 12, in <module>

    from ._montage import montage, montage2d

  File "C:\Users\THU -27\AppData\Local\Programs\Python\Python36\lib\site-


packages\skimage\util\_montage.py", line 2, in <module>

    from .. import exposure

  File "C:\Users\THU -27\AppData\Local\Programs\Python\Python36\lib\site-


packages\skimage\exposure\__init__.py", line 1, in <module>

    from .exposure import histogram, equalize_hist, \

  File "C:\Users\THU -27\AppData\Local\Programs\Python\Python36\lib\site-


packages\skimage\exposure\exposure.py", line 4, in <module>

    from ..color import rgb2gray

  File "C:\Users\THU -27\AppData\Local\Programs\Python\Python36\lib\site-


packages\skimage\color\__init__.py", line 1, in <module>

    from .colorconv import (convert_colorspace,

  File "C:\Users\THU -27\AppData\Local\Programs\Python\Python36\lib\site-


packages\skimage\color\colorconv.py", line 59, in <module>

    from scipy import linalg

ModuleNotFoundError: No module named 'scipy'

Thank you

Want
2 toRleave
E P LYa comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 56/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

nanthiniganesan
30/11/2018 05:26 PM

Hi, 

ModuleNotFoundError: No module named 'scipy'  -- is an exception

This exception generally means that speci ed module is not found .

For your case , scipy is not available. So use pip install scipy command to install the same.

Then next you will same error for matplotlib , do the same

1 R E P LY

JiangBo Shi
26/11/2018 12:27 PM

when I try to use the LDA to implement the Dimension reduction on the training data, my accuray
is down to 0.157 .

here is the process of Dimension reduction:

images32_tmp=np.array([image. atten() for image in images32])

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA

lda=LDA(n_components=49) 

images32_tmp=lda. t_transform(images32_tmp, labels)

images32_tmp = [transform.resize(image, (7,7)) for image in images32_tmp]

images32_tmp=np.array(images32_tmp)

what is the problem?  Why the accuray is decreaing ?

1 R E P LY

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 57/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Erlend Nikolaisen
20/12/2018 08:47 PM

The menu apear an disapear randomly and the page then moves up and down with it on my
Samsung Galaxy tab. That make this page unreadable.

1 R E P LY

Agostino Bruno
08/01/2019 08:47 PM

Hi, 

i tried to follow the tutorial, and i just go through until the script reported below. I do not
understand why I didn't get back any output, neither an error message.

import tensor ow as tf

import numpy as np

import os

import skimage

def load_data(data_directory):

    directories=[d for d in os.listdir(data_directory)

                 if os.path.isdir(os.path.join(data_directory,d))]

    labels=[]

    images=[]

    for d in directories:

        label_directory=os.path.join(data_directory,d)

         le_names=[os.path.join(label_directory,f)

                    for
Want to leave f inaos.listdir(label_directory)
comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 58/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

                    if f.endswith(".ppm")]

        for f in le_names:

            images.append(skimage.data.imread(f))

            labels.append(int(d))

        return images,labels

    ROOT_PATH="/Ago/ProgettiPersonali/TensorFlow/tutorial"

    train_data_directory=os.path.join(ROOT_PATH,"Traf cSigns/Training")

    test_data_directory=os.path.join(ROOT_PATH,"Traf cSigns/Testing")

    images,labels = load_data(train_data_directory)

    images=np.array(images)

    

    print(images.ndim)

1 R E P LY

Андрей Таранов
03/02/2019 07:55 PM

it tooks quite a lond time to read all the images from les. for me it's about 1 minute.. just
maybe wait  a bit...

1 R E P LY

john choi
19/01/2019 11:40 PM

This might be very useful in understanding Tensor ow. However, if I would like to run the program
in le form, like runing C programs, instead of Interactive form, I have to learn the ways to do
programming in le form, creating, modifying, and running the tensor ow program. How can I do
it? Long time ago I was working as a 'C' programmer
Want to leave a comment?
1 R E P LY
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 59/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Sumit Kumar
09/04/2019 12:01 PM

easy to understand!!!!

1 R E P LY

Bikramaditya Padhi
11/04/2019 06:45 PM

Awesome

1 R E P LY

Konark Nigam
23/04/2019 10:11 AM

name 'skimage' is not de ned

please help 

1 R E P LY

Ahmed Hassen
02/05/2019 10:45 AM

pip install scikit-image

1 R E P LY

RAJESH SAHU
10/05/2019 03:57 PM

good explanation for the new comer to tensor ow

1 R E P LY

Want to leave a comment?


Raja Sekar
24/05/2019 07:12 PM
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 60/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Hi,

Thank you for this nice tutorial. I am new to Machine Learning.

How can we export the .tf/.t ite les from python?

I have asked the same question here : https://stackover ow.com/questions/56293855/how-to-


generate-tf-t ite- les-from-python.

Thanks in advance.

1 R E P LY

Matteo Drusiani
11/06/2019 08:36 PM

Hi! When I try to run the section " Modeling The Neural Network" of the Jupyter Notebook
related to this tutorial I get 

images_flat: Tensor("Flatten_16/flatten/Reshape:0", shape=(?, 784), dtype=float32)


logits: Tensor("fully_connected_7/Relu:0", shape=(?, 62), dtype=float32)
loss: Tensor("Mean_14:0", shape=(), dtype=float32)
predicted_labels: Tensor("ArgMax_7:0", shape=(?,), dtype=int64)

as results of the instructions

print("images_ at: ", images_ at) 

print("logits: ", logits)

print("loss: ", loss)

print("predicted_labels:", correct_pred)

I would like to visualize the real values of images_ at, logits, loss, correct_pred. I tried to move the
"print" instructions after the instruction "sess.run(tf.global_variables_initializer())" of the
"Running The Neural Network" but I got the same results.
What is wrong? I didn't modify the code of the Jupyter Notebook

1 R E P LY

Aamira Abid
13/06/2019 12:02 PM
Want to
Check outleave a comment?
the interesting private fb downloader  https://vid u.com/private-downloader.php 

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 61/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp
1 R E P LY

Oskar Paulsson
15/06/2019 03:29 PM

When I try to run the script for the load_data function I get an error message saying "NameError:
name 'os' is not de ned" at the line:

 train_data_directory = os.path.join(ROOT_PATH, "Traf cSigns/Training") 

Please help!

1 R E P LY

Andrea Ciufo
19/06/2019 04:41 AM

I still receive this error mes sage "Impossible to see the speci ed path" 

both using :

ROOT_PATH = r"C:\\Users\AndreaCiufo\PythonProject\Tensor ow"

ROOT_PATH = "C:\\Users\AndreaCiufo\PythonProject\Tensor ow"

I tried to gure out the problem before asking, without useful results. 

Thanks Andrea 

FileNotFoundError: [WinError 3] Impossibile trovare il percorso specificato: 'C:\\\\Us

1 R E P LY

Si Le
20/06/2019 04:15 AM

Excellent article.

1 R E P LY

Harvey Jones
21/06/2019
Want 04:56
to leave PM
a comment?
Yup Yes this is a great article about tensor ow
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 62/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

1 R E P LY

Shawn Young
02/07/2019 12:01 PM

Hi there,  thanks for this wonderful tutorial and I learned a lot. However, I wonder what if I want
 to deal with colored images rather than grayscale? What should I do?

1 R E P LY

Vahidahamad Maniyar
24/07/2019 04:14 PM

  image = images[labels.index(label)]  .... get error of this line of code ... as there in to attribute in the
numpy.ndarry 

2 R E P LY

alex wong
12/08/2019 11:53 AM

very useful for beginners like me.

1 R E P LY

Mich Po
02/09/2019 12:32 AM

Hey, I tried to run your Jupyter notebook but I immediately got errors for missing packages
watermark. However when i did pip install watermark in PyCharm it showed I already have it I
dont understand why we need to use Jupyter and Pycharm together, and who the modules that
work on one IDE dont work in the other

When I try to run in pycharm I get a lot of other errors, can you please just post a full python le of
the code without jupyter so we can run it in pycharm, since jupyer is not even included in pycharm
anymore.

1 R E P LY

Felix Onroy
03/09/2019 04:14 PM
Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 63/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

There is an incompatibility between Skimage and numpy versions greater than 1.16.0. This results
in a continuous ImportError in the above code used to load the data

1 R E P LY

surjit kumar
26/09/2019 09:50 PM

thanks,very nice tutorial

1 R E P LY

Saima Wani
27/09/2019 06:48 PM

  Thank you I

1 R E P LY

Jamal Bradshaw
13/10/2019 05:37 AM

nice

1 R E P LY

Jamal Bradshaw
13/10/2019 05:37 AM

this is not for beginners JUST S-u -c -K My D -i -c -K

1 R E P LY

Jamal Bradshaw
13/10/2019 05:39 AM

this is not for beginners JUST S u c K My D i c K I HAGTE YOU

1 R E P LY

Jamal Bradshaw
13/10/2019 05:42 AM

SHE MADE ME MAD AF. JUST TRANSLTE THIS GUYS


Want
TY MĄŻtoMASZ,
leave aŻE
comment?
JEJ JESZCZE, ALE JESZCZE NIE JEDZIESZ? DOBRZE ILLAPUJĘ MOJEGO
Dicka NA TWARZ PRZYCZYNA TO JEST TWARDE I NIE DLA POCZĄTKUJĄCEGO
https://www.datacamp.com/community/tutorials/tensorflow-tutorial 64/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

1 R E P LY

Natta Wang
01/11/2019 11:15 AM

In 2.0 how to ` atten` data, because `tf.compat.v1` doesn't have `contrib` anymore?

1 R E P LY

Scott Straley
05/11/2019 06:10 AM

Did you source your plane vector illustration from


https://www.ese.wustl.edu/~nehorai/Porat_A_Gentle_Introduction_to_Tensors_2014.pdf ?  A
reference would be nice.

1 R E P LY

Natta Wang
05/11/2019 07:34 AM

Do you plan to update this article to use Tensor ow 2.0.0 soon?

I really need it.

1 R E P LY

Sadeeq Khan
23/11/2019 12:51 PM

How it is multiply with each 

1 R E P LY

Subscribe to RSS

About Terms Privacy

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 65/66
12/14/2019 TensorFlow Tutorial For Beginners (article) - DataCamp

Want to leave a comment?

https://www.datacamp.com/community/tutorials/tensorflow-tutorial 66/66

You might also like