top of page
Writer's pictureJoseph Muller III

Tensorflow Hitchhike

While I was working on an Android mobile application, I stumbled across the Android Developer’s Challenge. The focus of the challenge at the time (November 2019) was how on-device machine learning could help people get things done and even though my app was designed without machine learning features, I figured jamming some artificial intelligence into my basic social media app would give me some valuable experience. Here’s that hitchhiking journey.

The Optimized Journey (~30 min)

This is the path I would have taken if I knew what I know now…



Follow the Tensorflow Install Instructions

This is a reasonable first step.



Install Python 3.6.3

Install the 64 bit version of Python 3.6.3. Make sure to select to include Pip with your install and add it to you PATH variable. Also download the Jetbrains IDE.



Create a New Project in Jetbeans

After creating a new project, navigate to project interpreter screen:

File -> Settings -> Project -> Project Interpreter

Add a new interpreter that inherits global site-packages.



Install TensorFlow and Test

Use the special package URL for your version of Python (3.6.3) and platform (86x_64) to install TensorFlow.

As long as all of your variables are set up correctly, testing should be a breeze.

The Hitchhiker’s Journey (Like 4 hours)

This is the path I actually took to get started with Tensorflow…

  1. Red – Obstacles I couldn’t have avoided

  2. Yellow- Obstacles I could have avoided if I read carefully

  3. Green – Wow. Actual progress



Follow the Tensorflow Install Instructions

This seemed like a reasonable first step.



Install Python 3.8.0

I could have sworn I’ve downloaded Python several times but I’m frequently cleaning up my hard drives so maybe I didn’t think it was important.

The downloads page on the python site has more lines than I know what to do with but the first link is for the 3.8.0 version of Python for Windows. Perfect.



Realize I need pip

My bad. the Tensorflow instructions mention that I’ll need pip and its possible to include it with the Python install.

Control Panel -> Add or Remove Programs -> Uninstall Python 3.8.0 

Let’s do this again. I go back to the Python page, pick the 3.8.0 version, check the box to include pip this time and finish the installation.



Pip doesn’t work

I forgot what happened here but it was annoying.



Tensorflow download doesn’t work

God dangit.

Error: Could not find a version that satisfies the requirement tensorflow (from versions: ) No matching distribution found for tensorflow

Stack overflow again. Apparently the newest version of Python doesn’t support Tensorflow? I guess I’ll be uninstalling Python again and downgrading to 3.6.3.



Can’t install Python 3.6.3

What the hell. Can’t download Python 3.6.3 because there is an existing version of Python 3.6.3 somewhere on my computer…I guess I did install this at one point. Uninstall everything Python and start fresh with 3.6.3.



Same issue

I think at this point I went to sleep because I had already spent an hour trying to figure this out.

In the morning I read that some installation mechanisms require the URL of the TensorFlow Python package so I decided I’d try this approach.

Above is the path I tried using.



Tensorflow still won’t download

Error: Tensorflow installation error: not a supported wheel on this platform

I had a moment here where I really debated if this was worth it…I guess so. What else can stack overflow do for me.

Okay, so apparently “pip uses the wheel’s filename to determine compatibility and the format is:”

tensorflow-{version}-{python version}-none-{your platform}.whl 

In my path above, my platform was listed as amd64 which is wrong. It needed to be “x86-64” – nope – “x86_64”. Holy god.



Swirl

I accidentally downloaded the 32 bit of Python 3.6.3 and Tensorflow only works with 64 bit systems. Rinse and mf repeat.



Run the Tensorflow test

The install instructions on TensorFlow’s website say to run a line of code to confirm that TensorFlow has been properly installed. Well I do that and hit another error.

Error: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2



Python interpreter is invalid

Just when I thought my life was back on track, the gods of the digital age smack me in the mouth. Because I installed, uninstalled, and shuffled Python versions so many times, my Python interpreter became invalid…

Error: Cannot retrieve the version of the detected SDK

Stack overflow for the 15th time today – I need to update my interpreter from the Settings -> Project screen. According to this site, the interpreter is the bread and butter of Python.



Realize what the interpreter is

I admit I probably should have known what this is by now but it’s basically an advanced calculator you can open by typing python at the command prompt. Cool. Bunch of reference material below:

  1. REPL: Read – Eval – Print Loop

  2. #Comments

  3. / Float Division

  4. // Int Division (Floor)

  5. % Remainder Division

  6. _ Last Value in Interpreter



Modules and Functions

This is what I’ve been waiting to learn and it’s all pretty simple, thankfully.

  1. 1 – Write your code in text file with the .py extension. For instance, testing.py. This is called a module.

  2. 2 – Define your functions using the “def fun():” structure

  3. 3 – At the interpreter, import your module by typing “import <module>” (omit the .py extension)

  4. 4 – Use the functions in the module by referencing the module name (ex. testing.fun1)

Finally feel like I’m learning something. Feeling some kinda way.



Tensorflow won’t Import

I did what you asked of me. What else do you want?!

At the Python console in Jetbrains, I tried typing “import tensorflow as tf”. I got hit with the following error;

Error: ModuleNotFoundError: No module named ‘tensorflow’

This lead me to do some more investigation on where modules are imported from and I came across this question in Stack Overflow. I finally realized the utility of the PYTHONPATH environment variable – its an efficient way of referencing all of your Python modules from different Python projects….I think.

Assuming my guess was right, I created a new environment variable called PYTHONPATH and added the site-packages path to it. To get to the environment variables, just type “environment” at the start menu.



Are you kidding me?

That didn’t resolve the issue but I could feel I was getting close to figuring it out. It seemed like my project wasn’t detecting ANY of the packages in the path I added so I did some more searching and realized that when setting up an interpreter for a virtual environment, you need to check the box to “inherit global site-packages” and I must not have done that the first time.

File -> Settings -> Project -> Project Interpreter 

Select the settings cog, show all, and then add a new interpreter. I also learned you can type help(“command”) in the Python console and get a bunch of documentation so this wasn’t a total waste of time.



Import TensorFlow

Oh hell yeah, it worked.

Feels good man.



Download the Sample Data Set and Train Model

Surprisingly, I didn’t run into any issues during this step and my model was trained to recognize articles of clothing to 97.57% accuracy. Shiiiiii…….

Well, that was fun.

1 view0 comments

Recent Posts

See All

Comments


bottom of page