aymericdamien / TensorFlow-Examples

TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: unsupported operand type(s) for +: 'dict_values' and 'dict_values'

Billy1900 opened this issue · comments

when I run this file tensorflow_v2/notebooks/3_NeuralNetworks/neural_network_raw.ipynb Link. the error occured, TypeError: unsupported operand type(s) for +: 'dict_values' and 'dict_values'.
How can I solve this?

my tf version 2.1.0, python 3.7

@Billy1900 it happens because the notebooks were originally developed using Python 2.7.

So, if you run the notebook with a Python2.7 kernel, it will run flawlessly.

Also it fails on Python 3.7 due to some changes between Python2.7 and Python3.7:

  • On Python2.7, dictionary.values() returns an object from list class;
  • On Python3.7, dictionary.values() returns an object from dict_values class;

So to fix that problem, you can simply change line:

trainable_variables = weights.values() + biases.values()

by this content:

trainable_variables = list(weights.values()) + list(biases.values())

It solves the problem... Hope that helps.

@Billy1900 it happens because the notebooks were originally developed using Python 2.7.

So, if you run the notebook with a Python2.7 kernel, it will run flawlessly.

Also it fails on Python 3.7 due to some changes between Python2.7 and Python3.7:

  • On Python2.7, dictionary.values() returns an object from list class;
  • On Python3.7, dictionary.values() returns an object from dict_values class;

So to fix that problem, you can simply change line:

trainable_variables = weights.values() + biases.values()

by this content:

trainable_variables = list(weights.values()) + list(weights.values())

It solves the problem... Hope that helps.

trainable_variables = list(weights.values()) + list(weights.values()) or trainable_variables = list(weights.values()) + list(biass.values())?

it should be trainable_variables = list(weights.values()) + list(biass.values()) and it works, thanks!

Variables to update, i.e. trainable variables.

#trainable_variables = weights.values() + biases.values()
trainable_variables = list(weights.values()) + list(biases.values())