PlaidML accuracy not improving - python

When I run my code on Colab and on my machine using the CPU the accuracy of the network improves but when running the same code using PlaidML the accuracy never improves.
My requirements.txt file is as follows:
scikit-learn
scikit-image
matplotlib
seaborn
ipython
jupyter
scipy
numpy
pandas
pillow
pydot
coremltools==3.0
plaidml==0.6.4
plaidbench==0.6.4
keras==2.2.4
tensorflow==1.14
My imports are as follows:
import os
os.environ["KERAS_BACKEND"] = "plaidml.keras.backend"
import keras
import numpy as np
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import *
from keras import optimizers, callbacks
%matplotlib inline
import matplotlib.pyplot as plt
from keras.applications.mobilenet import MobileNet
There must be an issue with my requirements or my imports.

Related

Importing Adam and ImageDataGenerator on google colab failed

I'm implementing a UNet neural network but I'm having some issues while importing libraries. I found a solution for a couple of them, but I still have a problem with these two imports:
from tensorflow.keras.optimizers import Adam
#Import "tensorflow.keras.optimizers" could not be resolved(reportMissingImports)
from tensorflow.keras.preprocessing.image import ImageDataGenerator
#Import "tensorflow.keras.preprocessing.image" could not be resolved(reportMissingImports)
I've already imported:
import tensorflow as tf
from tensorflow import keras
from keras import layers
import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
import numpy as np
Any idea? I've tried to change but it still raises an error.

ModuleNotFoundError: No module named 'tensorflow' on Jupyter Notebook

when I try to import keras on a Jupyter notebook I receive this error message: ModuleNotFoundError: No module named 'tensorflow'.
I need to use keras to build an LSTM model fora project and am a beginner in python so I don't know how to get around this error. I have tried to install tenserflow and keras into an environment on anaconda but I receive the same error. For reference, I am using a Mac.
My code:
#Import libraries used
import math
import pandas as pd
import pandas_datareader.data as web
import datetime as dt
import numpy as np
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense, LSTM
Any help would be greatly appreciated!

AttributeError: module 'keras.engine.base_layer' has no attribute 'BaseRandomLayer'

Context - I was getting errors when saving/loading EfficientNetB7 and one of the articles I saw suggested installing tf-nightly. Well that really blew things up in my Google Colab! I uninstalled tf-nightly, restarted my runtime, and now when I go to run my import cell, I get the errors below.
I reinstalled tensorflow 2.6.0.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-5d853ee59f92> in <module>()
11 import tensorflow as tf
12 from tensorflow import keras
---> 13 from tensorflow.keras import Model
14 from tensorflow.keras.models import Sequential
15 from tensorflow.keras.utils import to_categorical
11 frames
/usr/local/lib/python3.7/dist-packages/keras/layers/core/dropout.py in <module>()
24
25 #keras_export('keras.layers.Dropout')
---> 26 class Dropout(base_layer.BaseRandomLayer):
27 """Applies Dropout to the input.
28
AttributeError: module 'keras.engine.base_layer' has no attribute 'BaseRandomLayer'
I also had an issue with this import before:
from tensorflow.keras import backend as keras
Here are all my imports:
import os
import glob
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.transform import resize
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.losses import categorical_crossentropy
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout, BatchNormalization
from tensorflow.keras.callbacks import ModelCheckpoint, LearningRateScheduler
from datetime import datetime
from sklearn.metrics import confusion_matrix, accuracy_score, f1_score, precision_score, recall_score
import skimage.io as io
import skimage.transform as trans
from tensorflow.keras import models
from tensorflow.keras import layers
from tensorflow.keras import optimizers
from tensorflow.keras.models import *
from tensorflow.keras.layers import *
from tensorflow.keras.optimizers import *
from tensorflow.keras.callbacks import ModelCheckpoint, LearningRateScheduler
from tensorflow.keras import backend as keras
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from keras_preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers.schedules import ExponentialDecay
import scipy.misc as sc
import h5py
from sklearn.semi_supervised import LabelSpreading
from sklearn.model_selection import GridSearchCV
from tensorflow.keras.applications import * #Efficient Net included here
import shutil
from sklearn import model_selection
from tqdm import tqdm
# import warnings
# warnings.filterwarnings("ignore", category=DeprecationWarning)
Try rolling back the python version to 3.6. If you are using Anaconda run
conda install python=3.6
Then install keras
pip install keras==2.0.8
Worked for me in Ubuntu.
I was able to get rid of the issue after installing tensorflow==2.8.0.

Wrong tensorflow version used after !pip install tf-nightly

I'm using some code written by my lecturer & I'm running it on a GPU in Google Colab. At the beginning of the code the tf-nightly package is installed using !pip install tf-nightly. Afterwards, the following packages are imported and the version of tf used is printed out as follows:
from tensorflow import keras
from tensorflow.keras import layers
# Helper libraries
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from mpl_toolkits.axes_grid1 import make_axes_locatable
print(tf.__version__)
For some reason, sometimes the version of tf used isn't always 2.3.xxx but instead sometimes it's 2.2 - but not always. Usually this happens when the tab has been open for a while but I haven't been using it.
This then causes the error
"AttributeError: module 'tensorflow.keras.preprocessing' has no attribute 'image_dataset_from_directory'" when I try to use this package.
Can anyone tell me how to stop this from happening/what to do if it does happen?
Thank you very much in advance.

In-code solution to remove warnings in my Python code

I have a deep learning python code (Anaconda3, Ubuntu 16.04) which uses TensorFlow for some machine learning algorithms on video inputs. It imports the following packages:
import time, os, glob, subprocess
import skvideo.io
import numpy as np
import tensorflow as tf
import time, cv2, librosa
import skvideo.io
import numpy as np
import tensorflow as tf
from sklearn.externals import joblib
When running, it get the following warning. How can I remove this warning (or hide it from printing)?
/home/user/anaconda3/lib/python3.5/site-packages/sklearn/base.py:311: UserWarning: Trying to unpickle estimator SVC from version 0.18.1 when using version 0.19.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)

Categories

Resources