Guns Germs And Steel
I’ve never been a big history fan. Too many names and dates to memorize. But now, free from the pressure of having to learn for the sake of getting good grad...
While working on the first part of my style-transfer project, I found out the hard way that TF is very sensitive to the network’s input’s data type.
I was tinkering around, trying to trace down a particular bug and in my frustration and tiredness, accidentally changed:
input_var = np.asarray(dummy_data, dtype=np.float32)
to:
input_var = np.asarray(dummy_data, dtype=np.float64)
I fed this value as an array directly into the vgg19 network, bypassing the use of a placeholder or variable. When I tried to restore the weights of the variables in the pre-trained vgg19 network, I was met with the following glaring error:
InvalidArgumentError: Expected to restore a tensor of type double, got a tensor of type float instead: tensor_name = vgg_19/conv1/conv1_1/biases
And a lot more information that I won’t copy here. Suffice it to say, the rest of the information was as unhelpful as this message. It took me a really long time to figure this out. Thanks to the message, I spent most of that time digging into the documenation for Savers and their restoring functionality. Eventually, with almost all other options exhausted, I accidentally reset the input to float32 and the error disappeared.
Always check that your input data is of type _float32_.
If you tried float16, the error wouldn’t be exactly the same but it would have a similar flavour:
InvalidArgumentError: Expected to restore a tensor of type half, got a tensor of type float instead: tensor_name = vgg_19/conv1/conv1_1/biases
int types would throw a different type of error earlier on, which is much more informative:
TypeError: Cannot create initializer for non-floating point type.
I’m not sure exactly why different floats return these weird errors but they do so watch out! If you’re not exactly sure of the type of your input data, be safe and cast it to float32.
If you’d like to experience these oddities for yourself, here’s a notebook for you to tinker with!
I’ve never been a big history fan. Too many names and dates to memorize. But now, free from the pressure of having to learn for the sake of getting good grad...
A little while ago, I read Letters from a Stoic by Seneca (translated and edited by Robin Campbell). I got a lot out of reading Letters and wanted to encoura...
I recently finished reading Every Tool’s a Hammer: Life Is What You Make It1 by Adam Savage. It was an energizing read and I highly recommend this book to fe...
CoordConv
Recently, I binged through the Culture series by Ian M. Banks. It was an amazing read and I thought a write up about it might help ground the experience and ...
I recently the following on Coursera: Learning How to Learn: Powerful mental tools to help you master tough subjects Mindshift: Break Through Obstacles ...
If you’re reading this, I’m assuming that you’ve read the paper Image Style Transfer Using Convolutional Neural Networks and have some familiarity with it.
While working on the second part of my style-transfer project, I needed to obtain the shape of a tensor. I decided to try using the tf.shape function.
If you’re reading this, I’m assuming that you’ve read the paper Image Style Transfer Using Convolutional Neural Networks and have some familiarity with it.
While working on the first part of my style-transfer project, I had: A new input variable which would have to be initialized from scratch. The VGG-19 ne...
While working on the first part of my style-transfer project, I found out the hard way that TF is very sensitive to the network’s input’s data type.
While working on the first part of my style-transfer project, I dealt with two main variable groups: The input variable which was the image I was optimizi...
While working on the first part of my style-transfer project, I used pyplot’s imshow to diplay images in the notebook. However, it took me a little bit of pl...
While working on the first part of my style-transfer project, I used Open CV’s cv2.imwrite to save images to disk. However, the images seemed to have a weird...
While working on the first part of my style-transfer project, I ran into lots of image issues. One of the issues was that cv2 uses a BGR channel order inste...
If you’re reading this, I’m assuming that you’ve read the paper Image Style Transfer Using Convolutional Neural Networks and have some familiarity with it.
Cue customary Hello World.