I'm taking a Microsoft PyTorch course and trying to implement on Kaggle Notebooks but I kept having the same error message over and over again: "ModuleNotFoundError: No module named 'onnxruntime'". I've checked everywhere possible if I could find a solution to it but none, I even tried installing it manually using pip in the notebook, but it's still not working. I've checked the official onnxruntime website and documentation but there's nowhere it states anything about something being outdated or any other issue. Someone help. My code won't run because it says "onnxruntime is not defined". Here are my imports:
%matplotlib inline
import torch
import onnxruntime
from torch import nn
import torch.onnx as onnx
import torchvision.models as models
from torchvision import datasets
from torchvision.transforms import ToTensor
and the code cell I'm trying to run
session = onnxruntime.InferenceSession(onnx_model, None)
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
result = session.run([output_name], {input_name: x.numpy()})
predicted, actual = classes[result[0][0].argmax(0)], classes[y]
print(f'Predicted: "{predicted}", Actual: "{actual}"')
And you can find the complete notebook here: https://www.kaggle.com/faisalalbasu/complete-model
the error occurs because "import" cannot find onnxruntime in any of the paths, check where import is searching and see if onnxruntime is in there.
check what path pip install installs to, that way in the future you won't have the same problem! :)
Related
import onnxruntime as rt
ort_session = rt.InferenceSession(
"my_model.onnx",
providers=["CUDAExecutionProvider"],
)
onnxruntime (onnxruntime-gpu 1.13.1) works (in Jupyter VsCode env - Python 3.8.15) well when providers is ["CPUExecutionProvider"]. But for ["CUDAExecutionProvider"] it sometimes(not always) throws an error as:
[W:onnxruntime:Default, onnxruntime_pybind_state.cc:578 CreateExecutionProviderInstance] Failed to create CUDAExecutionProvider. Please reference https://onnxruntime.ai/docs/reference/execution-providers/CUDA-ExecutionProvider.html#requirements to ensure all dependencies are met.
I tried following the provided link in the error, and tried different setups in the conda environment to test the code with various version combinations.
Replacing:
import onnxruntime as rt
with
import torch
import onnxruntime as rt
somehow perfectly solved my problem.
When i try to run the efficientNetv2 model
I got this erreur Error-message
AttributeError: module'tensorflow.keras.applications ' has no attribute 'efficientnet_v2'
Tensorflow version : tensorflow-gpu:2.6
The import is incorrect, you need to update it, it might have worked in older Keras versions,but the internal per-network modules inside keras.applications are not exposed anymore, so your correct import would be:
keras.applications.EfficientNetV2S
Or if you use tf.keras:
tf.keras.applications.EfficientNetV2S
For future reference, always check the documentation, for EfficientNetV2S the link is here.
install efficientnet in you env
!pip install keras-efficientnet
then you can import model as
import efficientnet.tfkeras as efc
done...
you can use prefix 'efc' for B0-B7
I've seen similar questions, but no solutions for this problem.
I'm using Google Colab:
!pip install pycaret
And this:
import time
import numpy as np
import pandas as pd
from pycaret.datasets import get_data
#from pycaret.time_series import TSForecastingExperiment
from pycaret.time_series import *
The last line returns the error: ModuleNotFoundError: No module named 'pycaret.time_series'
Does anyone know how to fix this?
Thanks in advance!
Please follow the instructions here: https://github.com/pycaret/pycaret#-pycaret-time-series-module-beta
Specifically, for the time being, the Time Series module needs to be installed separately in its own environment (i.e. not together with the main pycaret package), using:
!pip install pycaret-ts-alpha
Really sorry for my novice question.
I am trying to install a module in python for neo4j but I got an error.
here is the import :
from scripts.vis import vis_network
from scripts.vis import draw
Here is the error:
ModuleNotFoundError: No module named 'scripts'
I have tried "pip install scripts"
Thanks in advance
ModuleNotFoundError simply means the Python interpreter couldn't find the module. I suggest that you read about python modules and packaging here.
I have looked at the source code you pointed to and it works perfectly fine. I suspect your paths are not well set up.
Make sure that in you are running importing scripts.vis in app.py, the directory structure looks like this:
./scripts
./scripts/__init__.py
./scripts/vis.py
....
./app.py #in app.py, you can import as 'from scripts.vis import x'
Here's what it looks on my system:
app.py is successfully able to make the import from vis sub-module. You can use a IPython notebook, that should work fine too.
If you want to visualize the graph in the python environment (Jupyter), you can try using neo4jupyter library. Here you will use neo4jupyter.draw to visualize the graph.
Install !pip install neo4jupyter
For example:
import neo4jupyter
neo4jupyter.init_notebook_mode()
from py2neo import Node
nicole = Node("Person", name="Nicole", age=24)
drew = Node("Person", name="Drew", age=20)
graph.create(nicole | drew)
options = {"Person": "name"}
neo4jupyter.draw(graph, options)
You may find this useful:
https://github.com/merqurio/neo4jupyter
https://nicolewhite.github.io/neo4j-jupyter/hello-world.html
I am very frustrated by this error, what I did is getting the code from tensor flow tutorial to import moist:
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
However when I run the python shows:
File "/Users/kevinling/Desktop/Machine Learning/tensorflow.py", line 2, in
from tensorflow.examples.tutorials.mnist import input_data
ImportError: No module named examples.tutorials.mnist
When I check into the directory, the file is perfectly there:
And the directory is:
enter image description here
The input_data.py is like:
The input_data.py
Just rename your example from "tensorflow.py" to anything else and it will work. The interpreter is trying to import the necessary files from your script.
Did you already install tensorflow? If not, follow their install instructions or simply install using pip:
pip install tensorflow
Now, make sure you are NOT currently in a folder where tensorflow is located, and try running your script.
python your_script.py