module 'tensorflow_federated.python' has no attribute 'federated_computation' - python

I follow the instructions in the github that says to install Tensorflow Federated with Collab we need to install version 0.20.0 but I get this error when I try to run the toturials.
!pip install --quiet tensorflow-federated==0.20.0 # The latest version of tensorflow-federated is not working with the colab python version
!pip install --quiet --upgrade nest-asyncio
from __future__ import absolute_import, division, print_function
import collections
from six.moves import range
import numpy as np
import tensorflow as tf
# from tensorflow import compat
from tensorflow_federated import python as tff
np.random.seed(0)
tf.compat.v1.enable_v2_behavior()
tff.federated_computation(lambda: 'Hello, World!')()
Error:
module 'tensorflow_federated.python' has no attribute 'federated_computation'
What is the problem I don't understand? How can I install it on google colab. There is no resource for this problem.

Are you sure you need to import this
from tensorflow_federated import python as tff
instead of
import tensorflow_federated as tff
According to the Tensorflow docs, the federated_computation was under tensorflow_federated directly.

Related

Cannot import tensorflow_io

I am getting ModuleNotFoundError when I try to import tensorflow_io.
I tried to fix the error as described in ModuleNotFoundError: No module named 'tensorflow_io' but it didn't work with me
I did the following and I was able to have the module imported in my machine,
pip install tensorflow
pip install tensorflow_io
then in a file.py you can import them
import tensorflow as tf
import tensorflow_io as tfio
I figure you need the tensorflow module installed if you want to use the tensorflow_io.

Installed transforemers but cannot be imported on Google CoLab / StableDiffusion

I am trying to run the stablediffusion example from this link: https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb#scrollTo=zTDA0fvtuOIQ
!pip install diffusers==0.3.0
!pip install transformers scipy ftfy
!pip install "ipywidgets>=7,<8"
!pip install transformers
from google.colab import output
output.enable_custom_widget_manager()
from huggingface_hub import notebook_login
notebook_login()
I installed the required dependencies and restarted the runtime and then ran the following code:
import torch from diffusers import StableDiffusionPipeline pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=True)
But It spits out the following errors:
ImportError: cannot import name 'CLIPFeatureExtractor' from 'transformers' (/usr/local/lib/python3.7/dist-packages/transformers/init.py)
How should I fix the problem?

Detectron MetadaCatalog and DatasetCatalog import Failed

I'm trying the include of Detectron2.data on Google Colab. I made the connection for colab & my drive. And after that:
!pip install pyyaml
!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.7/index.html
It worked without any error.
i have been trying this;
import numpy as np
import os, json, cv2, random
from google.colab.patches import cv2_imshow
import detectron2
from detectron2.data import MetadataCatalog, DatasetCatalog
from detectron2.utils.visualizer import Visualizer
from detectron2 import model_zoo
But the outputs like this:
enter image description here
How can i fix that?
I fixed like this:
!pip install pyyaml==5.1
import torch, torchvision
print(torch.__version__, torch.cuda.is_available())
!gcc --version
import torch
assert torch.__version__.startswith("1.8")
!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.8/index.html
# exit(0) # After installation, you need to "restart runtime" in Colab. This line can also restart runtime
from: https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5#scrollTo=ZyAvNCJMmvFF

How to import BeamSearchDecoder after tensorflow update?

from tensorflow.contrib.seq2seq import BeamSearchDecoder as beam_search_decoder
gives
ModuleNotFoundError: No module named 'tensorflow.contrib'
The latest versions of Tensorflow do not contain contrib, so how can I use the function?
BeamSearchDecoder is now part of Tensorflow Addons, which should be installed separately via pip:
pip install tensorflow-addons
After that, you can use it either as you try here:
from tensorflow_addons.seq2seq import BeamSearchDecoder as beam_search_decoder
or directly as suggested in the documentation and the tutorial:
import tensorflow_addons as tfa
tfa.seq2seq.BeamSearchDecoder(...)

TFLearn import issue - no module core_rnn

I am testing out the TFLearn library for using TensorFlow but can't import it due to some config issue. I installed it as required in TFLearn tutorial though. Thankful for any help.
>>> import tflearn as tf
> import tflearn
File "//anaconda/lib/python2.7/site-packages/tflearn/__init__.py", line 4, in <module>
from . import config
ImportError: cannot import name config
This is caused due to incompatibilitiy of TFlearn and Tensorflow. They may be of different version. Hence, to resolve the issue, uninstall tensorflow and tflearn and reinstall them using the following code -
pip uninstall tflearn
pip uninstall tensorflow
pip install -I tensorflow==0.12.1
pip install -I tflearn==0.2.1

Categories

Resources