Tensorflow batch normalization backward compatibility - python

I am trying to train a semantic segmentation model using tensorflow 1.15.4 but when i try to load the model into tensorflow 1.5.0 using I get the following error:
ValueError: No op named FusedBatchNormV3 in defined operations.
What could be done to load the model in tensorflow with backward compatibility?

Related

How to use already trained tensorflow model for online learning and predictions without importing tensorflow

I have an custom Tensorflow model, which would work in an enviroment where tensorflow API would not be installed. I created a GUI which has 2 buttons.
First button. If new dataset will come the model should be trained on this dataset
Second button. Do predictions on some data.
The question is can I convert this tensorflow model to sklearn model because and use its fit() and predict() methods? in the enviroment is allowed to use only sklearn models and tensorflow is not installed.

How to convert Tensorflow 2.* trained with Keras model to .onnx format?

I use the Python 3.7.4 with TensorFlow 2.0 and Keras 2.2.4-tf to train my own CNN model. Everything goes fine. I can use e.g. model.save(my_model), and then use it in other Python scripts. Problem appears when I want to use trained model in OpenCV with its DNN module in C++. cv::dnn:readNetFromTensorflow(model.pb, model.pbtxt), takes as you can see two arguments, and I can't get the second .pbtxt file. So I decide to use .onnx format, because of its flexibility. The problem is that existing libraries keras2onnx takes only model from TensorFlow 1.*, and I want to avoid working with it. Example of code to convert it is presented below:
import tensorflow as tf
import onnx
import keras2onnx
model = tf.keras.models.load_model(my_model_folder_path)
onnx_model = keras2onnx.convert_keras(model, model.name)
onnx.save_model(onnx_model, model_name_onnx)
Is there some other ways to convert such model to onnx format?
The latest version of keras2onnx (in github master) supports TensorFlow 2.
You can install it like this:
pip install git+https://github.com/microsoft/onnxconverter-common
pip install git+https://github.com/onnx/keras-onnx
You need to create a file which can hold ONNX object. Visit https://github.com/onnx/tutorials/blob/master/tutorials/OnnxTensorflowExport.ipynb
import tensorflow as tf
import onnx
import keras2onnx
model = tf.keras.models.load_model('Model.h5')
onnx_model = keras2onnx.convert_keras(model, model.name)
file = open("Sample_model.onnx", "wb")
file.write(onnx_model.SerializeToString())
file.close()

Keras create dataset from CSV without TensorFlow

On every question and tutorial I have found, tf.data.Dataset is used for CSV files, but I am not using tensorflow, I am using PlaidML because my AMD GPU is not supported in ROCm. I have tried using the same code by doing
os.environ["KERAS_BACKEND"] = "plaidml.keras.backend"
from tensorflow import keras
but that still does not use the plaidml backend. How do I load this dataset: https://www.kaggle.com/keplersmachines/kepler-labelled-time-series-data into keras without tensorflow? Thank you. I check if the plaidml backend is used by looking at the output. If it says "Using plaidml.keras.backend backend", then it is using plaidml. Also, only plaidml recognizes my GPU, so tensorflow will use my CPU.

keras model weights 1.x to 2.x

I have a set of weights from a model developed in keras 1.10 with theano backend.
Right now I would like to use those weights in a more recent version of keras (2.2.4).
Just by loading them on the more recent version of keras the results are not the same (in 2.2.4 the results are not accurate). I can retrain the model but it would take some time. Is there some way to use the weights?
I tried to load the weights from 1.10 to 2.2.4 and it did not work. Also found a project on git:
https://gist.github.com/davecg/e33b9b29d218b5966fb8e2f617e90399
To update the weights from Keras 1.x to 2.x and also did not work.
Thanks for the answers.

How to load pretrained googlenet model in pytorch

I'm trying to finetune a GoogleNet network over a specific dataset but I'm having trouble loading it. What I try now is:
model = torchvision.models.googlenet(pretrained=True)
However I get an error:
AttributeError: module 'torchvision.models' has no attribute 'googlenet'
I have the latest version of torchvision but reinstalled just to be sure, the error is still there.
You can instead use the GoogLeNet inception_v3 model ("Rethinking the Inception Architecture for Computer Vision"):
import torchvision
google_net = torchvision.models.inception_v3(pretrained=True)

Categories