I am trying to read a dicom file
File link:
https://gist.github.com/Yash0270/da5953a116171f0950cbfcc53bf367fe
Code I am trying to use:
import matplotlib.pyplot as plt
import pydicom
import pydicom.data
# Full path of the DICOM file is passed in base
base = "./"
pass_dicom = "img4.dcm" # file name is 1-12.dcm
# enter DICOM image name for pattern
# result is a list of 1 element
filename = pydicom.data.data_manager.get_files(base, pass_dicom)[0]
ds = pydicom.dcmread(filename)
plt.imshow(ds.pixel_array, cmap=plt.cm.bone) # set the color map to bone
plt.show()
Error message:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-6-129bb47e9b15> in <module>
13 ds = pydicom.dcmread(filename)
14
---> 15 plt.imshow(ds.pixel_array, cmap=plt.cm.bone) # set the color map to bone
16 plt.show()
2 frames
/usr/local/lib/python3.8/dist-packages/pydicom/dataset.py in _convert_pixel_data_without_handler(self)
1529 )
1530
-> 1531 raise RuntimeError(msg + ', '.join(pkg_msg))
1532
1533 last_exception = None
RuntimeError: The following handlers are available to decode the pixel data however they are missing required dependencies: GDCM (req. GDCM), pylibjpeg (req. )
I tried with all these commands but still handlers are not found
!pip install pylibjpeg
!pip install pylibjpeg gdcm
!pip install numpy Pillow
!pip install python-gdcm
I even tried these commands
from pydicom import dcmread
ds = dcmread('img4.dcm')
ds.file_meta.TransferSyntaxUID
>1.2.840.10008.1.2.4.70
which means gdm+numpy or numpy+pylibjpeg would work as per https://pydicom.github.io/pydicom/dev/old/image_data_handlers.html
but it's not.
What am I doing wrong?
Related
I am starting with a ML model and importing libraries. Every library is working fine except MGLEARN which throws error:
ModuleNotFoundError: No module named 'MGLEARN'.
I didn't pip install anything.
import sys
print("Python version: {}".format(sys.version))
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
print("pandas version: {}".format(pd.__version__))
import matplotlib
print("matplotlib version: {}".format(matplotlib.__version__))
import numpy as np
print("NumPy version: {}".format(np.__version__))
import scipy as sp
print("SciPy version: {}".format(sp.__version__))
import IPython
print("IPython version: {}".format(IPython.__version__))
import sklearn
print("scikit-learn version: {}".format(sklearn.__version__))
import mglearn
The output I get
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 17
15 import sklearn
16 print("scikit-learn version: {}".format(sklearn.__version__))
---> 17 import MGLEARN
ModuleNotFoundError: No module named 'MGLEARN'
Pip install anything gives error
!pip install mglearn
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[7], line 1
----> 1 get_ipython().system('pip install mglearn')
File /lib/python3.10/site-packages/IPython/core/interactiveshell.py:2542, in InteractiveShell.system_piped(self, cmd)
2537 raise OSError("Background processes not supported.")
2539 # we explicitly do NOT return the subprocess status code, because
2540 # a non-None value would trigger :func:`sys.displayhook` calls.
2541 # Instead, we store the exit_code in user_ns.
-> 2542 self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=1))
File /lib/python3.10/site-packages/IPython/utils/_process_posix.py:129, in ProcessHandler.system(self, cmd)
125 enc = DEFAULT_ENCODING
127 # Patterns to match on the output, for pexpect. We read input and
128 # allow either a short timeout or EOF
--> 129 patterns = [pexpect.TIMEOUT, pexpect.EOF]
130 # the index of the EOF pattern in the list.
131 # even though we know it's 1, this call means we don't have to worry if
132 # we change the above list, and forget to change this value:
133 EOF_index = patterns.index(pexpect.EOF)
AttributeError: module 'pexpect' has no attribute 'TIMEOUT'
I'm trying to follow "Build an Mario AI Model with Python | Gaming Reinforcement Learning" by Nicholas Renotte tutorial and can't move on beacouse of some error.
Here is my code:
!pip install gym_super_mario_bros==7.3.0 nes_py
# Import the game
import gym_super_mario_bros
# Import the Joypad wrapper
from nes_py.wrappers import JoypadSpace
# Import the simplified controls
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
# Setup game
env = gym_super_mario_bros.make('SuperMarioBros-v0')
env = JoypadSpace(env, SIMPLE_MOVEMENT)
and this line of code: env = gym_super_mario_bros.make('SuperMarioBros-v0') couses following error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_16900\3897944130.py in <module>
1 # Setup game
----> 2 env = gym_super_mario_bros.make('SuperMarioBros-v0')
3 env = JoypadSpace(env, SIMPLE_MOVEMENT)
D:\Anaconda\envs\gamesAi\lib\site-packages\gym\envs\registration.py in make(id, max_episode_steps, autoreset, new_step_api, disable_env_checker, **kwargs)
623 # If we have access to metadata we check that "render_mode" is valid
624 if hasattr(env_creator, "metadata"):
--> 625 render_modes = env_creator.metadata["render_modes"]
626
627 # We might be able to fall back to the HumanRendering wrapper if 'human' rendering is not supported natively
KeyError: 'render_modes'
I've already tried using python 3.7 instead of 3.9 and reinstalling packages
Most of the custom envs are not yet ready for the 0.25 Version. Changing the version to 0.24.1 should solve the issue.
Try:
pip install gym=0.24.1
Kind regards
I'm not being able to use the read_file method of geopandas. below is the code and the stack trace
import geopandas as gpd
path_to_data = gpd.datasets.get_path("nybb")
gdf = gpd.read_file(path_to_data)
error trace:
ImportError Traceback (most recent call last)
Input In [5], in <module>
1 path_to_data = gpd.datasets.get_path("nybb")
----> 2 gdf = gpd.read_file(path_to_data)
4 gdf
File ~/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/geopandas/io/file.py:166, in _read_file(filename, bbox, mask, rows, **kwargs)
104 def _read_file(filename, bbox=None, mask=None, rows=None, **kwargs):
105 """
106 Returns a GeoDataFrame from a file or URL.
107
(...)
164 by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.
165 """
--> 166 _check_fiona("'read_file' function")
167 filename = _expand_user(filename)
169 if _is_url(filename):
File ~/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/geopandas/io/file.py:80, in _check_fiona(func)
78 def _check_fiona(func):
79 if fiona is None:
---> 80 raise ImportError(
81 f"the {func} requires the 'fiona' package, but it is not installed or does "
82 f"not import correctly.\nImporting fiona resulted in: {fiona_import_error}"
83 )
ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: dlopen(/Users/junaid/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/fiona/ogrext.cpython-39-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/proj#7/lib/libproj.19.dylib
Referenced from: /opt/homebrew/Cellar/gdal/3.4.1_1/lib/libgdal.30.dylib
Reason: tried: '/opt/homebrew/opt/proj#7/lib/libproj.19.dylib' (no such file), '/usr/local/lib/libproj.19.dylib' (no such file), '/usr/lib/libproj.19.dylib' (no such file)
It looks like geopandas is referening an older version of PROJ. I used to have proj 7.2 but now have 8.2.1 installed.
Also I have the following versions of fiona and gdal
fiona 1.8.19
GDAL 3.3.3
any help would be much appreciated
Have you tried to install the Fiona package? Because it requires this package from your error.
I am having trouble identifying what causes this problem. Basically, I am working on a jupyter notebook that runs on a conda environment.
I have created a file "Myutils.py" which has some helper function for later use. the file is saved in the same folder as the notebook.
Giving that I have made the necessary imports in the notebook as well as in the Myutils file, I still got a name error:
In notebook:
first cell:
import cv2
import pytesseract
import numpy as np
import os
import matplotlib.pyplot as plt
from MyUtils import *
%matplotlib inline
then:
img = cv2.imread('./yolov5/runs/detect/exp/crops/address/422.jpg')
plt.imshow(remove_noise(img))
produces this error message:
NameError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17892/550149434.py in <module>
1 img = cv2.imread('./yolov5/runs/detect/exp/crops/address/422.jpg')
----> 2 plt.imshow(remove_noise(img))
~\Documents\Machine Learning\Projects\CIN OCR\MyUtils.py in remove_noise(image)
5 def get_grayscale(image):
6 return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
----> 7
8 # noise removal
9 def remove_noise(image):
NameError: name 'cv2' is not defined
And, in the Myutils.py, we have:
import cv2
import numpy as np
# get grayscale image
def get_grayscale(image):
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
By doing from Myutils import * you are overriding the earlier import cv2.
I don't know if this is what is causing your bug, but it's worth avoiding import * unless you are certain there are no conflicts - see e.g:
Why is "import *" bad?
Symfony\Component\Process\Exception\ProcessFailedException
================ Error Output: ================
line 15 if loaded_model.predict(X)[0][0] >= 0.5: ^ SyntaxError: invalid syntax
The original code is if loaded_model.predict(X)[0][0] >= 0.5:
After change the code to >=, the another error shows,
Code: 1(General error),Output: ================ Error Output: ================ Traceback (most recent call last)
line 1, in <module> from keras.models import load_model File
line 1, in <module> from keras.models import load_model ImportError: No module named models
Please help
#keras.py
from keras.models import load_model
from cv2 import imread, resize
from numpy import zeros
# Path of the Image To Test
img_path = "wound.jpg"
loaded_model = load_model('./content/wound_classification')
# Load and preprocess Image
X = zeros((1, 300, 300, 3))
X[0] = resize(imread(img_path), (300, 300))
X[0] = X[0] / 255.0
# Predict Image
if loaded_model.predict(X)[0][0] >= 0.5:
print("Wound is Non Chronic")
else:
print("Wound is Chronic")
The code works well in my computer but after upload to plesk control panel. It doest works, does anyone have this problem and solution?
or need to install keras in plesk control panel? and how to install because google didn't shows the way to install keras in plesk control panel.
you have to install keras using pip (e.g. pip install keras or pip install <zip file> from the releases https://github.com/keras-team/keras/releases)
you don't have the right keras package installed. that's why your code does not work.
also, rename your keras.py file to be something else as your are confusing python imports