How do I use a previous version of Keras (0.3.1) on Colaboratory? - keras

I tried pip installing 0.3.1, but when I print the version it outputs 2.1.4.
!pip install keras==0.3.1
import keras
print keras._version__
I am trying to train deepmask (https://github.com/abbypa/NNProject_DeepMask/) for which I specifically need 0.3.1.

Note that if you've already loaded keras, then the second import statement has no effect.
So first !pip install keras==0.3.1, then restart your kernel (ctrl-m . or Runtime -> Restart runtime) and then things should work as expected.

Related

Segfault in pytorch on M1: torch.from_numpy(X).float()

I'm using an M1.
I'm trying to use pytorch for a conv net.
I have a numpy array that I'm trying to turn into a torch tensor.
When I call
torch.from_numpy(X)
pytorch throws an error that it got a double when it expected a float.
When I call
torch.from_numpy(X).float() on a friends computer, everything is fine.
But when I call this command on my computer, I get a segfault.
Has anyone seen this / know what might be happening / know how to fix?
What's your pytorch vision? I've encountered the same problem on my Macbook Pro M1, and my pytorch version is 1.12.0 at first. The I downgraded it to version 1.10.0 and the problem is solved. I suspect this has something to do with the compatibility with M1 in newer torch versions.
Actually I first uninstalled torch using pip3 uninstall torch and then reinstalled with pip3 install torch==1.10.0
But if you are using torchvision or some other affiliated packages, you may also need to downgrade them too.

When downloading MNIST, I can't get the "processed" folder

I am following a tutorial in here https://www.youtube.com/watch?v=IQpP_cH8rrA
I followed all the initial steps (except I am in VS not in Colab) but I stop pretty soon because when running:
torchvision.datasets.MNIST('./', download=True)
I get only the raw folder, not the processed one (which should contain training.pt and test.pt).
Can anybody help?
I am running on python 3.8.10, torch version 1.10.1, torchvision 0.11.2
PS: I found the same issue here https://github.com/pytorch/vision/issues/4685
should I really downgrade torchvision to 0.9.1 to have both folders?
if yes, how can I just downgrade torchvision from cmd, without uninstall torch and install everything back?
I found this work around, downloading the data from tensorflow and then just switching the data types so you can follow along the tutorial again. hope this helps
import tensorflow as tf
import torch
import numpy as np
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(x_train.shape)
images = torch.from_numpy(x_train)
ground_truth = torch.from_numpy(y_train)
print(images.shape)
print(ground_truth.shape)
`
This works in my notebook, hopefully it does for you too
I am not sure if this answer will help anyone but this was my solution to it (after lots of trying and searching in the internet, I am not too experienced):
(I used anaconda prompt)
I created a virtual environment called "test" for python 3.6:
conda create -n test python=3.6
activate test
I installed the recommended torchvision version on it:
pip install torchvision==0.9.1
I ran my program in the virtual environment:
python yourprogram.py
I am sure this is not the best solution to exist but it worked for me and was very easy as it is just a few lines in anaconda prompt.

why YOLO v3 Keras buggy?

I am running this colab from Roboflow: https://colab.research.google.com/drive/1ByRi9d6_Yzu0nrEKArmLMLuMaZjYfygO#scrollTo=WgHANbxqWJPa
The code should be as-is, but i get errors at the end...
I suspect a TF versioning issue, but how do i know which version of TF i should install instead?
It should use TF1:
%tensorflow_version 1.x
But
!python -c 'import keras;
print(keras.version)'
returns: Using TensorFlow backend. 2.2.4
What am i doing wrong here? Unistall TF & reinstall which version?
Thanx
Fred

AttributeError: module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip'

I use Tensorflow 2.1.0
In this code
data_augmentation = tf.keras.Sequential([
tf.keras.layers.experimental.preprocessing.RandomFlip('horizontal'),
tf.keras.layers.experimental.preprocessing.RandomRotation(0.3)
])
I find this error:
AttributeError: module 'tensorflow_core.keras.layers.experimental.preprocessing' has no attribute 'RandomFlip'
So how can I change it without changing version of tensorflow
To work your code as expected, firstly Tensorflow has to be upgrade to the latest version
! pip install tensorflow --upgrade
If you are looking for solution in TF 2.1.0, then there are two options are available
First solution: tf.image.random_flip_left_right ( horizontal flip)
tf.image.random_flip_left_right(
image, seed=None)
Second solution: tf.keras.preprocessing.image.ImageDataGenerator
tf.keras.preprocessing.image.ImageDataGenerator(
rotation_range=30, horizontal_flip=True)
! pip install tensorflow --upgrade --user
--user option can help you without the permission problem
Add this line to the importing section (of course after import tensorflow as tf)
tf.config.experimental_run_functions_eagerly(True)
Almost any tf.keras.layers.experimental.preprocessing.SomeClass in the listed classes here, should work.
But need to do sanity check with plotting results.

How to use densenet in Keras

I notice densenet has been added to keras (https://github.com/keras-team/keras/tree/master/keras/applications)and I want to apply it in my project but when I tried to import it in jupyter anaconda, I got an error saying:
module 'keras.applications' has no attribute 'densenet'
it seems like densenet has not been incorporated into current version of keras.
Any idea how can I add it myself?
Densenet was added in keras version 2.1.3. What version of keras are you running?
Have you tried to update keras with pip install keras --upgrade since January?

Resources