Using tensorflow backend ошибка

«Using XXX backend» would print when I import keras.

import keras

Outputs:

Using TensorFlow backend.

But I clearly know what I am using.

How to disable it?

David Jones's user avatar

David Jones

4,7643 gold badges32 silver badges45 bronze badges

asked Jul 21, 2018 at 14:10

fmnijk's user avatar

2

Just using the code below.

import os
import sys
stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import keras
sys.stderr = stderr

answered Jul 28, 2018 at 1:39

fmnijk's user avatar

fmnijkfmnijk

4115 silver badges13 bronze badges

workaround for this problem:

stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import keras
sys.stderr = stderr

You can find more info in keras issues here

answered Jul 21, 2018 at 14:17

Tal Avissar's user avatar

Tal AvissarTal Avissar

10.1k6 gold badges46 silver badges71 bronze badges

If you are using Tensorflow 2.0, then you might get an error saying AttributeError: module 'tf' has no attribute 'logging'

Unfortunately tf.logging has been removed from tensorflow 2.0. Please execute the below commands:

import logging
logger = tf.get_logger()
logger.setLevel(logging.ERROR)

answered Aug 23, 2019 at 4:40

Ankit Jain's user avatar

Ankit JainAnkit Jain

2282 silver badges3 bronze badges

You have two options:
First comment in here keras/backend/__init__.py the string print('Using TensorFlow backend.'), but of course this option is not suggested since you are going to edit code in the keras module.
The second option is:

import sys
stdout = sys.stdout
sys.stdout = open('/dev/null', 'w')
import keras
sys.stdout = stdout

It’s not elegant, but it works.

answered Jul 21, 2018 at 14:16

maurock's user avatar

maurockmaurock

5331 gold badge7 silver badges22 bronze badges

2

First comment in here «keras/backend/init.py» the string print(‘Using TensorFlow backend.’) it will work!!.. but it is not a permanent solution.

answered Oct 3, 2019 at 12:11

Abhishek Pandey's user avatar

0

Another way to hide keras printing «using Tensorflow backend»

Suggested here https://github.com/keras-team/keras/issues/1406

import ...

import os
from contextlib import redirect_stderr
with redirect_stderr(open(os.devnull, "w")):
    import keras

import ...
import ... 

answered Aug 30, 2021 at 10:00

Humza Naveed's user avatar

Include this line in your code. It will ignore the error.

tf.logging.set_verbosity(tf.logging.ERROR)

answered Aug 6, 2019 at 4:46

Ankit Jain's user avatar

Ankit JainAnkit Jain

2282 silver badges3 bronze badges

3

09.03.2020, 11:43. Показов 6364. Ответов 10


Студворк — интернет-сервис помощи студентам

Установила библиотеку tensorflow, она работает. Установила keras а при import keras пишет: Using TensorFlow backend.
а при import theano:
Traceback (most recent call last):
File «C:\Program Files\Python35\lib\configparser.py», line 1135, in _unify_values
sectiondict = self._sections[section]
KeyError: ‘blas’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File «C:\Program Files\Python35\lib\site-packages\theano\configparser.py», line 168, in fetch_val_for_key
return theano_cfg.get(section, option)
File «C:\Program Files\Python35\lib\configparser.py», line 778, in get
d = self._unify_values(section, vars)
File «C:\Program Files\Python35\lib\configparser.py», line 1138, in _unify_values
raise NoSectionError(section)
configparser.NoSectionError: No section: ‘blas’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File «C:\Program Files\Python35\lib\site-packages\theano\configparser.py», line 328, in __get__
delete_key=delete_key)
File «C:\Program Files\Python35\lib\site-packages\theano\configparser.py», line 172, in fetch_val_for_key
raise KeyError(key)
KeyError: ‘blas.ldflags’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File «<stdin>», line 1, in <module>
File «C:\Program Files\Python35\lib\site-packages\theano\__init__.py», line 124, in <module>
from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
File «C:\Program Files\Python35\lib\site-packages\theano\scan_module\__init__.py», line 41, in <module>
from theano.scan_module import scan_opt
File «C:\Program Files\Python35\lib\site-packages\theano\scan_module\scan_opt.py», line 60, in <module>
from theano import tensor, scalar
File «C:\Program Files\Python35\lib\site-packages\theano\tensor\__init__.py», line 17, in <module>
from theano.tensor import blas
File «C:\Program Files\Python35\lib\site-packages\theano\tensor\blas.py», line 155, in <module>
from theano.tensor.blas_headers import blas_header_text
File «C:\Program Files\Python35\lib\site-packages\theano\tensor\blas_headers.py», line 987, in <module>
if not config.blas.ldflags:
File «C:\Program Files\Python35\lib\site-packages\theano\configparser.py», line 332, in __get__
val_str = self.default()
File «C:\Program Files\Python35\lib\site-packages\theano\configdefaults.py», line 1448, in default_blas_ldflags
res = try_blas_flag(ret)
File «C:\Program Files\Python35\lib\site-packages\theano\configdefaults.py», line 1519, in try_blas_flag
flags=cflags, try_run=True)
File «C:\Program Files\Python35\lib\site-packages\theano\gof\cmodule.py», line 2244, in try_compile_tmp
comp_args)
File «C:\Program Files\Python35\lib\site-packages\theano\gof\cmodule.py», line 1804, in _try_compile_tmp
args = cls.compile_args()
File «C:\Program Files\Python35\lib\site-packages\theano\gof\cmodule.py», line 2003, in compile_args
native_lines = get_lines(«%s -march=native -E -v -» % theano.config.cxx)
File «C:\Program Files\Python35\lib\site-packages\theano\gof\cmodule.py», line 1987, in get_lines
for line in lines:
File «C:\Program Files\Python35\lib\site-packages\theano\compat\__init__.py», line 54, in decode_iter
yield x.decode()
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xcc in position 21: invalid continuation byte

Помогите пожалуйста исправить ошибку. Уже все перепробовала. g++ установлен.



0



I ran with the latest version of tensorflow and keras. I didn’t experience an import problem with theano as the backend. And when I put tensorflow as the backend, I saw the following message:

`
In [1]: import keras
Using TensorFlow backend.

AttributeError Traceback (most recent call last)
in ()
—-> 1 import keras

//anaconda/lib/python2.7/site-packages/keras/init.py in ()
1 from future import absolute_import
2
—-> 3 from . import activations
4 from . import applications
5 from . import backend

//anaconda/lib/python2.7/site-packages/keras/activations.py in ()
4 from . import backend as K
5 from .utils.generic_utils import deserialize_keras_object
—-> 6 from .engine import Layer
7
8

//anaconda/lib/python2.7/site-packages/keras/engine/init.py in ()
6 from .topology import Layer
7 from .topology import get_source_inputs
—-> 8 from .training import Model

//anaconda/lib/python2.7/site-packages/keras/engine/training.py in ()
22 from .. import metrics as metrics_module
23 from ..utils.generic_utils import Progbar
—> 24 from .. import callbacks as cbks
25 from ..legacy import interfaces
26

//anaconda/lib/python2.7/site-packages/keras/callbacks.py in ()
24 if K.backend() == ‘tensorflow’:
25 import tensorflow as tf
—> 26 from tensorflow.contrib.tensorboard.plugins import projector
27
28

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/init.py in ()
28 from tensorflow.contrib import deprecated
29 from tensorflow.contrib import distributions
—> 30 from tensorflow.contrib import factorization
31 from tensorflow.contrib import framework
32 from tensorflow.contrib import graph_editor

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/factorization/init.py in ()
22 from tensorflow.contrib.factorization.python.ops.clustering_ops import *
23 from tensorflow.contrib.factorization.python.ops.factorization_ops import *
—> 24 from tensorflow.contrib.factorization.python.ops.gmm import *
25 from tensorflow.contrib.factorization.python.ops.gmm_ops import *
26 # pylint: enable=wildcard-import

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/factorization/python/ops/gmm.py in ()
25 from tensorflow.contrib.framework.python.framework import checkpoint_utils
26 from tensorflow.contrib.framework.python.ops import variables
—> 27 from tensorflow.contrib.learn.python.learn.estimators import estimator
28 from tensorflow.contrib.learn.python.learn.estimators import model_fn as model_fn_lib
29 from tensorflow.python.framework import constant_op

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/init.py in ()
85
86 # pylint: disable=wildcard-import
—> 87 from tensorflow.contrib.learn.python.learn import *
88 # pylint: enable=wildcard-import
89

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/init.py in ()
21
22 # pylint: disable=wildcard-import
—> 23 from tensorflow.contrib.learn.python.learn import *
24 # pylint: enable=wildcard-import

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/init.py in ()
23 from tensorflow.contrib.learn.python.learn import basic_session_run_hooks
24 from tensorflow.contrib.learn.python.learn import datasets
—> 25 from tensorflow.contrib.learn.python.learn import estimators
26 from tensorflow.contrib.learn.python.learn import graph_actions
27 from tensorflow.contrib.learn.python.learn import learn_io as io

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/init.py in ()
295 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
296 from tensorflow.contrib.learn.python.learn.estimators.constants import ProblemType
—> 297 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNClassifier
298 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNEstimator
299 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNRegressor

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/dnn.py in ()
27 from tensorflow.contrib.layers.python.layers import optimizers
28 from tensorflow.contrib.learn.python.learn import metric_spec
—> 29 from tensorflow.contrib.learn.python.learn.estimators import dnn_linear_combined
30 from tensorflow.contrib.learn.python.learn.estimators import estimator
31 from tensorflow.contrib.learn.python.learn.estimators import head as head_lib

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/dnn_linear_combined.py in ()
29 from tensorflow.contrib.layers.python.layers import optimizers
30 from tensorflow.contrib.learn.python.learn import metric_spec
—> 31 from tensorflow.contrib.learn.python.learn.estimators import estimator
32 from tensorflow.contrib.learn.python.learn.estimators import head as head_lib
33 from tensorflow.contrib.learn.python.learn.estimators import model_fn

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py in ()
47 from tensorflow.contrib.learn.python.learn.estimators import tensor_signature
48 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
—> 49 from tensorflow.contrib.learn.python.learn.learn_io import data_feeder
50 from tensorflow.contrib.learn.python.learn.utils import export
51 from tensorflow.contrib.learn.python.learn.utils import saved_model_export_utils

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/learn_io/init.py in ()
19 from future import print_function
20
—> 21 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_data
22 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_labels
23 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import HAS_DASK

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/learn_io/dask_io.py in ()
24 try:
25 # pylint: disable=g-import-not-at-top
—> 26 import dask.dataframe as dd
27 allowed_classes = (dd.Series, dd.DataFrame)
28 HAS_DASK = True

//anaconda/lib/python2.7/site-packages/dask/dataframe/init.py in ()
1 from future import print_function, division, absolute_import
2
—-> 3 from .core import (DataFrame, Series, Index, _Frame, map_partitions,
4 repartition)
5 from .io import (from_array, from_bcolz, from_array, from_bcolz,

//anaconda/lib/python2.7/site-packages/dask/dataframe/core.py in ()
36 return_scalar = ‘return_scalar
37
—> 38 pd.computation.expressions.set_use_numexpr(False)
39
40

AttributeError: ‘module’ object has no attribute ‘computation’
`

However, I did not experience any error when simply import tensorflow directly:

import tensorflow

«Using XXX backend» would print when I import keras.

import keras

Outputs:

Using TensorFlow backend.

But I clearly know what I am using.

How to disable it?

David Jones's user avatar

David Jones

4,7643 gold badges32 silver badges45 bronze badges

asked Jul 21, 2018 at 14:10

fmnijk's user avatar

2

Just using the code below.

import os
import sys
stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import keras
sys.stderr = stderr

answered Jul 28, 2018 at 1:39

fmnijk's user avatar

fmnijkfmnijk

4115 silver badges13 bronze badges

workaround for this problem:

stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import keras
sys.stderr = stderr

You can find more info in keras issues here

answered Jul 21, 2018 at 14:17

Tal Avissar's user avatar

Tal AvissarTal Avissar

10.1k6 gold badges46 silver badges71 bronze badges

If you are using Tensorflow 2.0, then you might get an error saying AttributeError: module 'tf' has no attribute 'logging'

Unfortunately tf.logging has been removed from tensorflow 2.0. Please execute the below commands:

import logging
logger = tf.get_logger()
logger.setLevel(logging.ERROR)

answered Aug 23, 2019 at 4:40

Ankit Jain's user avatar

Ankit JainAnkit Jain

2282 silver badges3 bronze badges

You have two options:
First comment in here keras/backend/__init__.py the string print('Using TensorFlow backend.'), but of course this option is not suggested since you are going to edit code in the keras module.
The second option is:

import sys
stdout = sys.stdout
sys.stdout = open('/dev/null', 'w')
import keras
sys.stdout = stdout

It’s not elegant, but it works.

answered Jul 21, 2018 at 14:16

maurock's user avatar

maurockmaurock

5331 gold badge7 silver badges22 bronze badges

2

First comment in here «keras/backend/init.py» the string print(‘Using TensorFlow backend.’) it will work!!.. but it is not a permanent solution.

answered Oct 3, 2019 at 12:11

Abhishek Pandey's user avatar

0

Another way to hide keras printing «using Tensorflow backend»

Suggested here https://github.com/keras-team/keras/issues/1406

import ...

import os
from contextlib import redirect_stderr
with redirect_stderr(open(os.devnull, "w")):
    import keras

import ...
import ... 

answered Aug 30, 2021 at 10:00

Humza Naveed's user avatar

Include this line in your code. It will ignore the error.

tf.logging.set_verbosity(tf.logging.ERROR)

answered Aug 6, 2019 at 4:46

Ankit Jain's user avatar

Ankit JainAnkit Jain

2282 silver badges3 bronze badges

3

Issue

I program facial recognition and to use the «facenet_keras.h5» file I have to go through tensorflow but this error blocks me. help please, thank you.

this is the code:

import os
from os import listdir
from PIL import Image as Img
from numpy import asarray
from numpy import expand_dims
from keras.models import load_model
import numpy as np

import pickle
import cv2

#charger classifier et facenet_keras


HaarCascade = cv2.CascadeClassifier(cv2.samples.findFile(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'))
MyFaceNet = load_model("facenet_keras.h5")


folder = 'photos/' #chemin dossier photos
database = {}

for filename in listdir(folder):

    path = folder + filename
    gbr1 = cv2.imread(path)

    visage = HaarCascade.detectMultiScale(gbr1, 1.1, 4)

    if len(visage) > 0:
        x1, y1, width, height = visage[0]
    else:
        x1, y1, width, height = 1, 1, 10, 10

    x1, y1 = abs(x1), abs(y1)
    x2, y2 = x1 + width, y1 + height

    gbr = cv2.cvtColor(gbr1, cv2.COLOR_BGR2RGB)
    gbr = Img.fromarray(gbr)  # conversion file OpenCV en PIL
    gbr_array = asarray(gbr)  #convert en tab

    face = gbr_array[y1:y2, x1:x2]  #prendre face fotsiny

    face = Img.fromarray(face)  # retour en img
    face = face.resize((160, 160))
    face = asarray(face)

    #normaliser entree
    face = face.astype('float32')
    mean, std = face.mean(), face.std() #moyenne et ecart type
    face = (face - mean) / std

    # envoie des entree a facenet
    face = expand_dims(face, axis=0)
    signature = MyFaceNet.predict(face)

    database[os.path.splitext(filename)[0]] = signature

myfile = open("data.pkl", "wb")
pickle.dump(database, myfile)
myfile.close()

myfile = open("data.pkl", "rb")
database = pickle.load(myfile)
myfile.close()

I program facial recognition and to use the «facenet_keras.h5» file I have to go through tensorflow but this error blocks me. help please, thank you.I program facial recognition and to use the «facenet_keras.h5» file I have to go through tensorflow but this error blocks me. help please, thank you.I program facial recognition and to use the «facenet_keras.h5» file I have to go through tensorflow but this error blocks me. help please, thank you.I program facial recognition and to use the «facenet_keras.h5» file I have to go through tensorflow but this error blocks me. help please, thank you.I program facial recognition and to use the «facenet_keras.h5» file I have to go through tensorflow but this error blocks me. help please, thank you.I program facial recognition and to use the «facenet_keras.h5» file I have to go through tensorflow but this error blocks me. help please, thank you.

this is the error:

Using TensorFlow backend.
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:458: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:459: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:460: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:461: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:462: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:465: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
2022-10-12 15:26:25.360069: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
C:\Users\Zouzou\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\models.py:252: UserWarning: No training configuration found in save file: the model was *not* compiled. Compile it manually.
  warnings.warn('No training configuration found in save file: '

Solution

I finally solved the problem. I had badly installed keras. pip install keras or reinstall tensorflow.

Answered By – h81 edrick

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Понравилась статья? Поделить с друзьями:
  • Using system data entity ошибка
  • Usb util for ps2 ошибка
  • Using render selected with empty selection ошибка
  • Usb unknown device windows 7 код ошибки 43
  • Uwow ошибка подключения к серверу