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)
Related
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.
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?
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()
I'm trying to load a trained .onnx model (from a neural-style-transfer algorithm) into cv2. I've seen that there is a
cv.dnn.readNetFromONNX()
function, but there is no such function in cv2. I can't seem to import or load opencv as cv, and as such can't seem to load my model in cv2. Does anyone know a solution?
I've basically trained a model with
https://github.com/pytorch/examples/blob/master/fast_neural_style/neural_style/neural_style.py#L122-L150
this script, and made an export of an onnx model by adding
torch.onnx.export(style_model, dummy_input, "chipsoft_mod.onnx", verbose=True)
Now I want to run the trained model trough the cv2 reader, but I fail spectacularly.
Update your opencv to a newer version. It should help.
pip install opencv-python==4.1.0.25
I am using Torch7 library for implementing neural networks. Mostly, I rely on pre-trained models. In Lua I use torch.load function to load a model saved as torch .t7 file. I am curious about switching to PyTorch( http://pytorch.org) and I read the documents. I couldn't find any information regarding the mechanisms to load a pre-trained model. The only relevant information I was able to find is this page:http://pytorch.org/docs/torch.html
But the function torch.load described in the page seems to load a file saved with pickle. If someone has additional information on loading .t7 models in PyTorch, please share it here.
The correct function is load_lua:
from torch.utils.serialization import load_lua
x = load_lua('x.t7')
As of PyTorch 1.0 torch.utils.serialization is completely removed. Hence no one can import models from Lua Torch into PyTorch anymore. Instead, I would suggest installing PyTorch 0.4.1 through pip in a conda environment (so that you can remove it after this) and use this repo to convert your Lua Torch model to PyTorch model, not just the torch.nn.legacy model that you cannot use for training. Then use PyTorch 1.xx to do whatever with it. You can also train your converted Lua Torch models in PyTorch this way :)