Error output (Symfony\Component\Process\Exception\ProcessFailedException) - python

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

Related

Not able to read a .DICOM file in python

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?

How to upgrade TF1 GAN notebook on Colab to TF2? It does't work because Colab is't supporting TF1 anymore

I was trying to run this notebook on colab,
https://colab.research.google.com/github/https-deeplearning-ai/GANs-Public/blob/master/C1W1_(Colab)_Inputs_to_a_pre_trained_GAN.ipynb ,
but first I got this :
ValueError: Tensorflow 1 is unsupported in Colab.
then I upgraded it using this script:
import tensorflow as tf
!tf_upgrade_v2 \
--intree stylegan/ \
--inplace
and I did comment these:
%tensorflow_version 1.x
tflib.init_tf()
but I got this one! and couldn't solve:
AttributeError: Can't get attribute 'Network' on <module 'dnnlib.tflib.network' from '/content/stylegan/dnnlib/tflib/network.py'>
Can somebody help?
# Clone the official StyleGAN repository from GitHub
!git clone https://github.com/NVlabs/stylegan.git
%tensorflow_version 1.x
import os
import pickle
import numpy as np
import PIL.Image
import stylegan
from stylegan import config
from stylegan.dnnlib import tflib
from tensorflow.python.util import module_wrapper
module_wrapper._PER_MODULE_WARNING_LIMIT = 0
# Initialize TensorFlow
tflib.init_tf()
# Go into that cloned directory
path = 'stylegan/'
if "stylegan" not in os.getcwd():
os.chdir(path)
# Load pre-trained network
# url = 'https://drive.google.com/uc?id=1MEGjdvVpUsu1jB4zrXZN7Y4kBBOzizDQ' # Downloads the pickled model file: karras2019stylegan-ffhq-1024x1024.pkl
url = 'https://bitbucket.org/ezelikman/gans/downloads/karras2019stylegan-ffhq-1024x1024.pkl'
with stylegan.dnnlib.util.open_url(url, cache_dir=config.cache_dir) as f:
print(f)
_G, _D, Gs = pickle.load(f)
# Gs.print_layers() # Print network details

cannot import name 'MSELossFlat' from 'fastai.layers'

I am running the code https://github.com/thiagodma/Pytorch_exs/blob/master/MultiTaskLearning/multitask_age_gender_ethnicity_resnet34.ipynb on Colab.
As I write:
from fastai import *
from fastai.vision import *
from fastai.layers import MSELossFlat, CrossEntropyFlat
from torchvision import transforms
import warnings
warnings.filterwarnings("ignore")
files_train = get_image_files("utkface_aligned_cropped/UTKFace")
files_valid = get_image_files("utkface_aligned_cropped/crop_part1")
I get the error:
ImportError Traceback (most recent call last)
<ipython-input-4-07ceae9afcad> in <module>()
1 from fastai import *
2 from fastai.vision import *
----> 3 from fastai.layers import MSELossFlat, CrossEntropyFlat
4 from torchvision import transforms
5 import warnings
ImportError: cannot import name 'MSELossFlat' from 'fastai.layers' (/usr/local/lib/python3.7/dist-packages/fastai/layers.py)
This is probably because you are referring to a code snippet that used the fastai v2 library. In the newest fastai, the MSELossFlat function can be imported at fastai.losses.
But since you are trying out an old code snippet, it's best to reproduce the execution enviroment of that code to get an expected result. I would recommend trying to install fastai v2 on your environment and execute the code again.

Why are the libraries in Utils.py not loading?

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?

when I practise the Mxnet turorial mnist, an error"ImportError: No module named mnist_demo" occurs

The tutorial is on http://mxnet.io/tutorials/python/mnist.html.
At this step:
"
from IPython.display import HTML
import cv2
import numpy as np
from mnist_demo import html, script
def classify(img):
img = img[len('data:image/png;base64,'):].decode('base64')
img = cv2.imdecode(np.fromstring(img, np.uint8), -1)
img = cv2.resize(img[:,:,3], (28,28))
img = img.astype(np.float32).reshape((1,1,28,28))/255.0
return model.predict(img)[0].argmax()
'''
To see the model in action, run the demo notebook at
https://github.com/dmlc/mxnet-notebooks/blob/master/python/tutorials/mnist.ipynb.
'''
HTML(html + script)
"
ImportError Traceback (most recent call last)
in ()
2 import cv2
3 import numpy as np
----> 4 from mnist_demo import html, script
5 def classify(img):
6 img = img[len('data:image/png;base64,'):].decode('base64')
ImportError: No module named mnist_demo
I do not know what is the reason and I cannot find the answer on Google.
Does anyone has any idea?
That was because the tutorial was not written in a single file. You should put the mnist_demo.py file together with your the tutorial notebook. The file could be found at mxnet-notebooks on the github site.
:P

Categories