Tag Archives: Python

AttributeError: ‘dict’ object has no attribute ‘iteritems’ – Python

Hey everyone,

Just running through object detection samples for Tensorflow and I encountered the following error:

Sample: https://github.com/GoogleCloudPlatform/tensorflow-object-detection-example

AttributeError: ‘dict’ object has no attribute ‘iteritems’

The issue seems to be that the sample hasn’t been made compatible with Python 3.x. Simply make the following change and it should work:

# Original
for cls, new_image in new_images.iteritems():

# Changed
for cls, new_image in new_images.items():

Thanks to the following StackOverflow post: https://stackoverflow.com/a/30418498/522859


Converting proto files to .py on Windows – Tensorflow

Hey everyone,

Ran into a bit of an issue today with Tensorflow:

ImportError: cannot import name preprocessor_pb2

Turned out that I hadn’t run some of the installing steps. I needed to use protoc to convert the proto directory files:

protoc object_detection/protos/preprocessor_pb2.proto --python_out=.

This turned out to be a bit of a headache as well, but thankfully a github post explained it all pretty well:

Here are the steps I followed to install it for windows:
(Prerequisite, you must have python, pip and)

Choose a Python release from here and download: Link here
– Extract the tar.gzor zip
– Open a cmd and pip install the following: pillow, lxml, jupyter, matplotlib
– Copy the protoc.exe from the protoc folder (you don’t need to do all the CMake steps you might have stumbled upon, it worked for me without them too) and paste it into your protos folder in the object detection directory.
– Run the protoc for each of those protos like “protoc object_detection/protos/*.proto –python_out=.”. . Note that you might encounter a problem with the paths and there’s two ways around that: Either move the protoc.exe two folders down or do the noobish thing that I did – copy the protos and paste them into a new directory inside the protos folder ‘object_detectionprotos’ so you would have a folder structure like’object_detectionprotosobject_detectionprotos’ (If it looks stupid but it works, it’s not stupid eh?) Note that *.proto might also not work and you might have to do each of them individually
– You are done. 🙂 Try to run something to see if you have any problems. You might have to install a manual version of numpyandscipy

GitHub Link: https://github.com/tensorflow/models/issues/1934

UnicodeDecodeError on RaspberryPi – Python

Hey everyone,

I ran into the following error while trying to read serial input on a Raspberry Pi hooked up to an Arduino via USB:

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0za8 in position 0: invalid start byte

The solution was as follows:

#buffer_string = ser.read().decode('utf-8')
buffer_string = ser.read().decode('utf-8', errors='replace')

Thanks to the following link: https://github.com/OpenBCI/OpenBCI_Python/issues/24

TensorFlow – KeyError: “The name ‘import/input’ refers to an Operation not in the graph.

Hey everyone,

Just another small error I’ve run into while testing out Tensorflow’s label image example (Tensorflow/tensorflow/examples/image_retraining/label_image.py):

KeyError: "The name 'import/input' refers to an Operation not in the graph.

This one thankfully doesn’t seem to be my fault. In label_image.py change the following lines:

# Line 78-79
input_layer = "input"
output_layer = "InceptionV3/Predictions/Reshape_1"

# Change to this
input_layer = "Mul"
output_layer = "final_result"

Once that’s done just rerun your script and it should all work. Thanks to the following post for the solution: https://github.com/tensorflow/tensorflow/issues/12736