AttributeError: module 'tensorflow' has no attribute 'streaming_accuracy' - python-3.x

accuracy = tf.streaming_accuracy (y_pred,y_true,name='acc')
recall = tf.streaming_recall (y_pred,y_true,name='acc')
precision = tf.streaming_precision(y_pred,y_true,name='acc')
confusion = tf.confuson_matrix(Labels, y_pred,num_classes=10,dtype=tf.float32,name='conf')
For the above code, I have received the same error in past few days.
Isn't the syntax same as it is in the API documentation for tensorflow?

try to use this instead (in a fresh python file, I would suggest create a /tmp/temp.py and run that)
from tensorflow.contrib.metrics import streaming_accuracy
and if this doesn't work then
either there is an installation problem (In which case reinstall)
or you are importing the wrong tensorflow module.

Related

from sparkdl import DeepImageFeaturizer

I need to use spark in transfer learning to train images ,the error is:
"nnot import name 'resnet50' from 'keras.applications' (/usr/local/lib/python3.7/dist-packages/keras/applications/init.py) "
i try to solve this question since one week, this one is coming from sparkdl, if you add to this file (sparkdl/transformers/keras_applications.py)
**
from tensorflow.keras.applications
**, it will be return normal, but this time you will see another error like
AttributeError: module 'tensorflow' has no attribute 'Session'
i tried on different IDE (Pycharm, Vs Code) but i got the same errors. there are different explications on Stackoverflow. but i'm totally confused now

module 'torch.cuda' has no attribute 'memory_summary'

I'm trying to measure the available space on each of my GPUs using torch.cuda module. However it is returning me the following error.
module 'torch.cuda' has no attribute 'memory_summary'
My code is below
if torch.cuda.is_available():
for i in range(torch.cuda.device_count()):
print(torch.cuda.get_device_name(i))
a = torch.cuda.memory_summary(torch.device('cuda:{}'.format(i)))
print(a)
Similarly memory_stats, mem_get_info and memory_reserved all are failing.
torch.cuda.memory_summary is introduced in Pytorch 1.4.0. So if your torch install is older than that you won't be able to use it.

AttributeError: module 'tensorflow' has no attribute 'contrib'

I am using someone else code (Code Link) which is implemented in Tensorflow1. I want to run this code into Tensorflow2 However I am getting this error:
mnist = tf.contrib.learn.datasets.load_dataset("mnist")
AttributeError: module 'tensorflow' has no attribute 'contrib'
I upgraded this code by using this instruction:
!tf_upgrade_v2 \
--infile /research/dept8/gds/anafees/MyTest.py \
--outfile /research/dept8/gds/anafees/MyTest2.py
Most things are updated, however generated report showed:
168:21: ERROR: Using member tf.contrib.distribute.MirroredStrategy in deprecated module tf.contrib. tf.contrib.distribute.MirroredStrategy cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
I search google; however, I could not find any suitable solution. I do not want to move back to Tensorflow1. Is there any alternate solution? Can anyone help?
Few libraries are deprecated in Tensorflow 2.x such tf.contrib, To make the code compatible with Tf 2 needs some changes in library.
Replace
tf.contrib.learn.datasets.load_dataset("mnist")
with
tf.keras.datasets.mnist.load_data()
And Replace
tf.contrib.distribute.MirroredStrategy
with
tf.distribute.MirroredStrategy(devices=None, cross_device_ops=None)

Keras with Theano on GPU

While trying to run my Keras code on GPU (CUDA installed), I am not able to execute the following statement, as has been suggested on many online references.
set THEANO_FLAGS="mode=FAST_RUN,device=gpu,floatX=float32" & python theanogpu_example.py
I am getting the following error.
ValueError: Invalid value ("FAST_RUN,device=gpu,floatX=float32") for configurati
on variable "mode". Valid options are ('Mode', 'DebugMode', 'FAST_RUN', 'NanGuar
dMode', 'FAST_COMPILE', 'DEBUG_MODE')
I have tried the other mode suggested as well from inside the code.
import theano
theano.config.device = 'gpu'
theano.config.floatX = 'float32'
I get the following error.
Exception: Can't change the value of this config parameter after initialization!
Apart from knowing how to make it run, I would also take this opportunity to ask a simpler question. How to know in Windows what is my device i.e. whether 'gpu' or 'gpu1' or 'gpu0'? I have tried all 3 for my case but it hasn't yielded result.
Any suggestions will be appreciated.
The best way is using THEANO_FLAGS before run code, because the config variables cannot be changed after importing Theano, try this:
import os
os.environ['THEANO_FLAGS'] = "device=cuda,force_device=True,floatX=float32"
import theano

rpy2: compatibiliity issue 2.0.6 vs 2.3.8

The following works in rpy2 2.0.6:
robjects.r('M = lm(...)')
M = robjects.r('M')
coefficients = M.r['coefficients'][0]
But after I upgraded to rpy2 2.3.8, the above fails with the message
AttributeError: 'ListVector' object has no attribute 'r'
What do I need to change to make this work in 2.3.8?
I am not certain that the code snippet you provide worked with rpy2-2.0.x
The documentation, section Introduction, is showing how to extract coefficients from linear models:
http://rpy.sourceforge.net/rpy2/doc-2.1/html/introduction.html#linear-models

Resources