Error while importing 'tensorflow_federated' on Google Colab Tutorial

Viewed 133

I've been working on the tutorial for Federated Learning for Image Classification, and while running the tutorial code on Google colab its giving me error while importing tensorflow_federated

Federated Learning for Image Classification

Code (getting error on line 4):

import collections
import numpy as np
import tensorflow as tf
import tensorflow_federated as tff

np.random.seed(0)

tff.federated_computation(lambda: 'Hello, World!')()

Error:

    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-35-a23308ec3f7c> in <module>()
      3 import numpy as np
      4 import tensorflow as tf
----> 5 import tensorflow_federated as tff
      6 
      7 np.random.seed(0)

6 frames
/usr/local/lib/python3.7/dist-packages/tensorflow_federated/python/common_libs/structure.py in <module>()
    263 
    264 def to_odict(struct: Struct,
--> 265              recursive: bool = False) -> collections.OrderedDict[str, Any]:
    266   """Returns `struct` as an `OrderedDict`, if possible.
    267 

TypeError: 'type' object is not subscriptable

I've tried updating the python version to 3.9 (as mentioned in some of the fixes available) but it didn't work.

Solved:

I followed this issue and installed the 0.20.0 version of tensorflow-federated which worked for me

!pip install --quiet tensorflow-federated==0.20.0
#!pip install --quiet --upgrade tensorflow-federated
!pip install --quiet --upgrade nest-asyncio

import nest_asyncio
nest_asyncio.apply()
0 Answers
Related