AttributeError: module 'torch.utils' has no attribute 'make_grid' - pytorch

I tried following along with the PyTorch transfer learning tutorial and found it pulled an error code when I brought up the make grid.

It's because it's out of date. As of 1.11.0 it has been moved to torchvision.utils.make_grid instead of torch.utils.make_grid
https://pytorch.org/vision/main/generated/torchvision.utils.make_grid.html?highlight=make_grid#torchvision.utils.make_grid

Related

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)

GluonCV, action recognition tutorial error

I've been trying to run the GluonCV tutorial for action recognition.
I didn't modify anything, but I'm getting an error at the very beginning of the script, when applying the transformation function to the image.
The error is:
AttributeError: 'list' object has no attribute 'shape'
To try and solve it, I wanted to replace the list with a single image, so I tried:
img = transform_fn(img.asnumpy())
plt.imshow(np.transpose(img, (1,2,0)))
plt.show()
but in this case, I get another error:
TypeError: Image data of dtype object cannot be converted to float
Any idea on how to fix it?
Thanks!
It seems I had to update gluoncv to a later version.
A little weird, because I installed it following the instruction on the tutorial page, but it works after the update.

Tensorboard: AttributeError: 'Model' object has no attribute '_get_distribution_strategy'

I'm getting this error when i use the tensorboard callback while training.
I tried looking for answers from posts related to tensorboard errors but this exact error was not found in any stackoverflow posts or github issues.
Please let know.
The following versions are installed in my pc:
Tensorflow and Tensorflow GPU : 2.0.0
Tensorboard: 2.0.0
I had the same problem and fixed it with this hack
model._get_distribution_strategy = lambda: None
It seems to be a bug on tensorflow's side.
https://github.com/tensorflow/tensorflow/pull/34870
Remove tensorboard callback for now.
This error mostly happens because of mixed imports from keras and tf.keras. Make sure that throughout the code exact referencing of libraries is maintained. For example instead of model.add(Conv2d()) try model.add(tf.keras.layers.Conv2D()) , applying this for all layers solved the problem for me.

module 'statsmodels.tsa.api' has no attribute 'arima_model'

I'm trying to use "statsmodels.api" to work with time series data and trying to fit a simple ARIMA model using
sm.tsa.arima_model.ARIMA(dta,(4,1,1)).fit()
but I got the following error
module 'statsmodels.tsa.api' has no attribute 'arima_model'
I'm using 'statsmodels' version 0.9.0 with 'spyder' version 3.2.8 I'd be pleased to get your help thanks
The correct path is :
import statsmodels.api as sm
sm.tsa.ARIMA()
You can view it using a shell that allows autocomplete like ipython.
It is also viewable in the example provided by statsmodels such as this one.
And more informations about package structure may be found here.

FailedPreconditionError: Table already initialized

I am reading data from tfrecords with dataset api. I am converting string data to dummy data with following code.
SFR1 = tf.feature_column.indicator_column(
tf.feature_column.categorical_column_with_vocabulary_list("SFR1 ",
vocabulary_list=("1", "2")))
But when i run my code, tensorflow is throwing following error.
tensorflow.python.framework.errors_impl.FailedPreconditionError: Table
already initialized. [[Node:
Generator/input_layer/SFR1 _indicator/SFR1 _lookup/hash_table/table_init
= InitializeTableV2[Tkey=DT_STRING, Tval=DT_INT64](Generator/input_layer/SFR1 _indicator/SFR1 _lookup/hash_table,
Generator/input_layer/SFR1 _indicator/SFR1 _lookup/Const,
Generator/input_layer/SFR1 _indicator/SFR1 _lookup/ToInt64)]]
[[Node: Generator2/IteratorGetNext =
IteratorGetNextoutput_shapes=[[?,10000,160]],
output_types=[DT_FLOAT],
_device="/job:localhost/replica:0/task:0/device:CPU:0"]]
I have tried many combinations to determine the source of problem. I understood that this problem occurs when model includes both tf.feature_column.categorical_column_with_vocabulary_list and dataset api. If i choose TFRecordReader instead of dataset, code is running.
When i search stackoverflow, I noticed that there is a similar issue. I am adding issue link below. As both problem are same, I didn't copy all my code. Below link includes enough data to explain my problem
Tensorflow feature columns in Dataset map Table already initialized issue
Thanks.
I came across the same issue. Then modified my code following the warning from Tensorflow and it works:
Creating lookup tables inside a function passed to Dataset.map() is not supported. Create each table outside the function, and capture it inside the function to use it.
Hope it would help.
This is issue with earlier version of TensorFlow, updating to TF2.0 should resolve this.
pip install --upgrade tensorflow

Resources