Tensorflow 2.0: Cannot Import tf.keras.utils.conv_utils - python

I'm using Tensorflow v2.1.0 which is compiled from source. How can I import any function from conv_utils module? E.g. convert_data_format(), conv_output_length(), normalize_tuple(), etc.
I wanna create my own convolution/pooling layer. "Everything" almost looks different when I wanna migrate from import keras to from tensorflow import keras.
This is what I did
> python -c "from tensorflow.keras.utils import conv_utils"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name 'conv_utils' from 'tensorflow.keras.utils' ...
Thank you.

Try this:
from tensorflow.python.keras.utils import conv_utils

This is the new way to import conv_utils in Tensorflow 2.1.0:
import tensorflow.keras.utils as conv_utils

Related

Tensorflow/Keras - ImportError: cannot import name 'Sequence'

Trying to run some machine learning examples so am importing some packages
sklearn version 0.22.1
tensorflow version 2.3.0
keras version 2.3.0
in the following way:
import os
import sys
import math
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlip.pyplot as plt
I am getting the import error:
ImportError: cannot import name 'Sequence'
Full traceback:
File "C:\Anaconda\lib\site-packages\keras\__init__.py", line 12, in <module>
from . import callbacks
File "C:\Anaconda\lib\site-packages\keras\callbacks\__init__.py", line 3, in <module>
from .callbacks import Callback
File "C:\Anaconda\lib\site-packages\keras\callbacks\callbacks.py", line 23, in <module>
from ..engine.training_utils import standardize_input_data
File "C:\Anaconda\lib\site-packages\keras\engine\training_utils.py", line 18, in <module>
from ..utils import Sequence
ImportError: cannot import name 'Sequence'
I have looked on line for help trying a few different tensorflow and keras versions. I have also tried:
import tensorflow.keras as keras
and import tensorflow.keras.utils import Sequence
without success

Cannot import name SummaryWriter

I'm using Pycharm with python 3.9, torch 1.8.1+cu111 and tensorboard 2.6.0.
When I try to import SummaryWriter by:
from torch.utils.tensorboard import SummaryWriter
I get the following error:
*Traceback (most recent call last):
File "/data/heisery/Yaronhome/PycharmProjects/CSSC_pytorch/tensorboard.py", line 18, in <module>
from torch.utils.tensorboard import SummaryWriter
File "/usr/local/lib/python3.8/dist-packages/torch/utils/tensorboard/__init__.py", line 1, in <module>
import tensorboard
File "/data/heisery/Yaronhome/PycharmProjects/CSSC_pytorch/tensorboard.py", line 18, in <module>
from torch.utils.tensorboard import SummaryWriter*
**ImportError: cannot import name 'SummaryWriter' from partially initialized module 'torch.utils.tensorboard' (most likely due to a circular import) (/usr/local/lib/python3.8/dist-packages/torch/utils/tensorboard/__init__.py)**
This is my import list:
import torch
import torch.nn as nn
from torch.utils.data import DataLoader
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import sys
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter('runs/mnist')
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
Bro
I have just solved a similar problem like yours. Just ensure that your filename is not set as 'tensorboard'.

cannot import name 'BatchNormalization' from 'keras.layers.normalization'

I'm learning ObjectDetection from this website
I have installed ImageAI,Tensorflow and Keras.
Then when I run this in python
from imageai.Detection import ObjectDetection
I got
Traceback (most recent call last):
File "", line 1, in
File "/home/carl/python-environments/env/lib/python3.9/site-packages/imageai/Detection/init.py", line 17, in
from imageai.Detection.YOLOv3.models import yolo_main, tiny_yolo_main
File "/home/carl/python-environments/env/lib/python3.9/site-packages/imageai/Detection/YOLOv3/models.py", line 8, in
from keras.layers.normalization import BatchNormalization
ImportError: cannot import name 'BatchNormalization' from 'keras.layers.normalization' (/home/carl/python-environments/env/lib/python3.9/site-packages/keras/layers/normalization/init.py)
Already tried:
from keras.layers.normalization.batch_normalization import BatchNormalization
from tensorflow.keras.layers import BatchNormalization
But still gave me the same error.
Tensorflow v2.8.0 support tf.keras.layers.BatchNormalization()
import tensorflow as tf
tf.keras.layers.BatchNormalization()

how to fix ModuleNotFoundError: No module named '__main__.unet_model'

I am trying to run ID Card Segmentation (MIDV-500) on my Ubuntu machine.
I need to run some files, and one of them is "train.py".
when i run "train.py" i get an error message on the Import section.
(the full repository - https://github.com/AdivarekarBhumit/ID-Card-Segmentation)
i try to import:
import cv2
import numpy as np
from sklearn.model_selection import train_test_split
from keras.callbacks import TensorBoard, ModelCheckpoint
from .unet_model import get_model
the error on the Terminal:
/Downloads/ID-Card-Segmentation/model$ python train.py
Using TensorFlow backend.
Traceback (most recent call last):
File "train.py", line 5, in <module>
from .unet_model import get_model
ModuleNotFoundError: No module named '__main__.unet_model'; '__main__' is not a package
how to fix that?

ModuleNotFoundError: No module named 'tensorflow.contrib' while making chatbot

So I'm following a tutorial and making a chatbot in python and I'm using the tflearn and tensorflow modules, and when I run my code I get the following error:
Traceback (most recent call last):
File "/home/user/Coding Projects/chatbot/main.py", line 6, in <module>
import tflearn
File "/home/user/.local/lib/python3.8/site-packages/tflearn/__init__.py", line 4, in <module>
from . import config
File "/home/user/.local/lib/python3.8/site-packages/tflearn/config.py", line 5, in <module>
from .variables import variable
File "/home/user/.local/lib/python3.8/site-packages/tflearn/variables.py", line 7, in <module>
from tensorflow.contrib.framework.python.ops import add_arg_scope as contrib_add_arg_scope
ModuleNotFoundError: No module named 'tensorflow.contrib'
I can't figure out how to fix it, and was wondering if someone could help me.
check your tensorflow version(you can to check it like that)
`
import tensorflow as tf
print(tf.__version__)
`
tensorflow contrib was removed from tensorflow 2.0 and its functionallty was moved to other modules.

Categories

Resources