I am trying to deploy a Web Application in Streamit Cloud and am facing the Error.
ERROR: pip's dependency resolver does not currently
take into account all the packages that are installed.
This behaviour is the source of the following dependency conflicts.
tensorflow 2.11.0 requires protobuf<3.20,>=3.9.2, but you have
protobuf 3.20.1 which is incompatible.googleapis-common-protos
1.57.0 requires protobuf!=3.20.0,!=3.20.1,!=4.21.1,!=4.21.2,!=4.21.3,
!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 3.20.1
which is incompatible.Successfully installed protobuf-3.20.1
WARNING: You are using pip version 22.0.3; however, version 22.3.1 is available.
You should consider upgrading via the '/home/appuser/venv/bin/python -m pip install --upgrade pip' command.
────────────────────────────────────────────────────────────────────────────────────────[10:51:17] 🐍
Python dependencies were installed from /app/tvs_credit_app/requirements.txt using pip.[10:51:17] 📦 Processed dependencies! Stopping...Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.[10:51:21] 🔄 Updated app!2022-12-31 10:51:29.902 Uncaught app exceptionTraceback (most recent call last): File "/home/appuser/venv/lib/python3.9/site-packages/soundfile.py", line 151, in <module> raise OSError('sndfile library not found')OSError: sndfile library not foundDuring handling of the above exception, another exception occurred:Traceback (most recent call last): File "/home/appuser/venv/lib/python3.9/site-packages/soundfile.py", line 178, in <module> _snd = _ffi.dlopen(_os.path.join(_path, '_soundfile_data', _packaged_libname))OSError: cannot load library '/home/appuser/venv/lib/python3.9/site-packages/_soundfile_data/libsndfile.so': /home/appuser/venv/lib/python3.9/site-packages/_soundfile_data/libsndfile.so: cannot open shared object file: No such file or directoryDuring handling of the above exception, another exception occurred:
There are two Errors : One is about protoBuff Version and the other is that the system is not able to identify the sndfile (might be used in librosa)
The requirements.txt file is :
librosa
matplotlib
numpy
pandas
Pillow
scipy
seaborn
streamlit
tensorflow
The app.py file looks like :
#Importing All Required Dependencies
import streamlit as st
from explore_page import show_explore_page
from predict_page import show_predict_page
page = st.sidebar.selectbox("Pages", ("Vehicle Price Estimator", "Explore More"))
if page=="Vehicle Price Estimator":
show_predict_page()
else:
show_explore_page()
The predict page is :
#Importing All Required Dependencies
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import scipy
from scipy import io, misc
import librosa
import tensorflow as tf
# import keras
from scipy.io.wavfile import read
from PIL import Image
import cv2
import pickle
#st.cache
def load_models():
model = tf.keras.models.load_model('audio_analysis_model.hdf5')
model_image = tf.keras.models.load_model('image_analysis_model.hdf5')
with open('saved', 'rb') as file:
data=pickle.load(file)
return (model,model_image,data)
models=load_models()
def show_predict_page():
st.title("Vehicle Price Estimator")
# MODEL 1 - Takes an Audio Input and Classify whether the defect present is Inner defect, Outer defect or Roller defect
uploaded_file = st.file_uploader("1. Upload an audio File of the Engine:")
if uploaded_file is not None:
# To read file as bytes:
bytes_data = uploaded_file.getvalue()
st.audio(bytes_data, format='audio/ogg')
# For reference, example.wav file is provided here
frequency = 10000
def feature_extract(l):
y = np.array(l)
sr = frequency
mfcc = librosa.feature.mfcc(y=y, sr=sr)
mfcc_scaled = np.mean(mfcc.T, axis=0)
return mfcc_scaled
a = read(uploaded_file)
audio= np.array(a[1],dtype=float)
test_dummy = feature_extract(audio)
test_dummy = test_dummy.reshape(1, -1)
model=models[0]
ans = model.predict(test_dummy)
# predicted class is stored in predicted_class
predicted_class = np.argmax(ans, axis=-1)
# Stores the parameter implying the defect detected through audio
audio_defect=0.0
if predicted_class==0:
st.subheader('No Defect Detected!')
elif predicted_class==1:
st.subheader('Inner Defect Detected!')
audio_defect=0.2
elif predicted_class==2:
st.subheader('Roller Defect Detected!')
audio_defect=0.2
else:
st.subheader('Outer Defect Detected!')
audio_defect=0.2
# MODEL 2 - Takes an Image Input and Classify whether the defect present is Minor, Moderate or Severe
uploaded_file2 = st.file_uploader("2. Upload an Image File of the Vehicle:")
if uploaded_file2 is not None:
# Reading the Image
image = Image.open(uploaded_file2)
st.image(image, caption='Car Image')
pic = Image.open(uploaded_file2)
# pix here denotes the resized image array
pix = np.asarray(pic)
pix = cv2.resize(pix, (80, 80))
im_data=np.array(pix).reshape(80,80,3)
im_data=im_data/255.0
# model_image is the image analysis model
model_image=models[1]
ans_im=model_image.predict(im_data.reshape(1,80,80,3))
pred_class_img = np.argmax(ans_im, axis=-1)
# parameter indicating the defect int the image
image_defect = 0.0
if pred_class_img == 0:
st.subheader('Minor Damage Detected!')
image_defect=0.2
elif pred_class_img == 1:
st.subheader('Moderate Damage Detected!')
image_defect= 0.3
elif pred_class_img == 2:
st.subheader('Severe Damage Detected!')
image_defect= 0.4
# The Same Logic can be easilt implemented for a Video Data as a Video is just several Frames of Images together
uploaded_file3 = st.file_uploader("OR, Upload an Video File of the Vehicle:")
if uploaded_file3 is not None:
video_bytes = uploaded_file3.read()
st.video(video_bytes)
# MODEL 3 = Decision Tree Regression Model to do Data Analysis as it gave the best result among all
# Designing all User Input Fields
# data stores 4 items:
# 1. A Data Analysis Model (MODEL 3)
# 2. A Standard Scaler as the input values can be of very different Ranges
# 3. A HashMap/Dictionary containing Model Name of Vehicle as keys and New Price of Vehicle as values
# 4. A List of Names of Vehicles
data=models[2]
model = data["model"]
scaling = data["scaling"]
priceMp = data["priceMap"]
model_names = data["names"]
# Taking User Inputs
col1, col2 = st.columns(2)
with col1:
name = st.selectbox( '3. Select Model of the Vehicle:', model_names)
fuel = st.selectbox(
'5. Select Fuel Type:',
('Petrol', 'Diesel', 'CNG'))
mileage = st.number_input('7. Enter Mileage in kmpl:')
with col2:
location = st.selectbox(
'4. Select nearest Location:',
('Chennai', 'Mumbai', 'Kochi', 'Delhi', 'Coimbatore','Kolkata', 'Jaipur', 'Ahmedabad', 'Hyderabad', 'Pune','Bangalore'))
owners = st.selectbox(
'6. Select Number of Owners:',
('1','2','3'))
cc = st.number_input('8. Enter CC of the Engine:')
years = st.slider('9. Numbers of years used: ', 0, 50, 1)
kms = st.number_input('10. Kilometers Driven:')
trans = st.selectbox(
'11. Select Transmission Type:',
('Manual', 'Automatic'))
# Converting Transmission Type, Location, Fuel into Integer Values
trans_val=0
if trans=='Manual' :
trans_val=0
else:
trans_val=1
new_price=priceMp[name]
dict_cities = { 'Kochi':0,'Mumbai':1,'Coimbatore':2, 'Hyderabad':3, 'Pune':4, 'Kolkata':5, 'Delhi':6, 'Chennai': 7, 'Jaipur':8, 'Ahmedabad':9, 'Bangalore':10 }
dict_fuel= {'Petrol':0,'Diesel':1,'CNG':2}
loc_val = dict_cities[location]
fuel_val = dict_fuel[fuel]
# Scaling the Values and Testing the trained Model with it
inp = np.array([[ loc_val, kms, fuel_val, trans_val, mileage, cc, new_price, years, owners ]])
df2 = pd.DataFrame(inp, columns = ['Location','Kilometers_Driven', 'Fuel_Type','Transmission','Mileage', 'Engine', 'New_Price', 'Years', 'Owners'])
transformed_data= scaling.transform(df2)
inp=np.array(transformed_data)
df2 = pd.DataFrame(inp, columns = ['Location','Kilometers_Driven', 'Fuel_Type','Transmission','Mileage', 'Engine', 'New_Price', 'Years', 'Owners'])
outp = model.predict(df2)
# Predicting the Final Price using all the outputs of the models
if st.button('GET ESTIMATED PRICE'):
ans=float(outp)
ans = ans - (ans*audio_defect)-(ans*image_defect)
if ans<=0.0:
ans=2.2
st.subheader(f"The Predicted Price is: Rs. {'%.2f'%ans} Lakhs.")
else:
st.write('')
I tried adding versions in requirements.txt file but the errors remained. Then I got the reqirements.txt file using pipreqs but still it gives error. I think the requirements.txt file needs some modifications as the app is working well locally.
THe entire code link :
https://github.com/bikramghosh-ux/TVS_CREDIT_APP
Related
I am trying to explore more learning paths and got to using matplotlab among others, however no matter what i try, various sites, etc. nothing seems to work. If anyone could explain why i'm getting a PIL error (yes i did read the error, and did everything searches mentioned) but nothing changed, so it would be greatly appreciated if someone could explain it to me, been trying for several hours now.
code:
# Created by Simon Ranger : December 15th 2022
"""
A general expense tracker that is displayed in table format as well as statistical format
How to use:
1. when prompt enter the data you want to be stored
Desired Output:
The user can add to a variety of lists relating to what expenses they wanted, food, general, etc. which will be both
displayed in a file and the terminal.
"""
# Imports required
from pandas import DataFrame as df, read_csv, DataFrame
import numpy as np
from matplotlib import pyplot as plt
from datetime import date
# create empty lists
GoodsOrServices: list | str = []
Prices: list | float = []
Dates: list | date = []
ExpenseType: list | str = []
# funct adding data to lists
def addingData(goodsOrServices: str, prices: int | float, dates, expenseType: str) -> None:
# appending to the lists
GoodsOrServices.append(goodsOrServices)
Prices.append(prices)
Dates.append(dates)
ExpenseType.append(expenseType)
def reportData() -> DataFrame:
expenseType = ""
# creating the dataframe
report = df()
report["GoodsOfServices"] = GoodsOrServices
report["Prices"] = Prices
report["Dates"] = Dates
report["ExpenseType"] = ExpenseType
report.to_csv("Expenses.csv")
# creating an array to loop through the data and pull the data for each section
FoodP = []
HouseP = []
TravelP = []
# reads the file that was created above
with open("Expenses.csv"):
read_csv("Expenses.csv", skiprows=1)
for _ in enumerate(report):
if expenseType == "Food":
Prices.append(FoodP)
elif expenseType == "Household":
Prices.append(HouseP)
elif expenseType == "Travel":
Prices.append(TravelP)
elif _:
print(f"Error: Something went wrong!")
# putting the data into a graph
plt.plot(report)
plt.legend()
plt.show()
return report
def main():
# option menu for the user
truth: int = 1
user: str = (input(f"Please enter your name: "))
while truth != 0:
options = int(
input(f"Welcome {user} to this interactive expense tracker!\nPlease select an option below:\n1. Add "
f"Food Expenses\n2. Household expenses\n3. Travel Expenses\n4. Display and Save the "
f"Expense Report\n0. Exit\nPlease enter the choice here: "))
match options:
case 0:
exit(f"Thank you for using the Expense Tracker. See you next time!")
case 1:
print(f"Adding Food\n")
expenseType = "Food"
case 2:
print(f"Adding Household\n")
expenseType = "Household"
case 3:
print(f"Adding Travel\n")
expenseType = "Travel"
case 4:
reportData()
# lets the user enter the data
if options == 1 or options == 2 or options == 3:
goodsOrservices = str(input(f"Enter the goods or services for the expense type {expenseType}:\n")).strip()
price = float(input(f"Enter the price of the goods or service:\n"))
today = date.today()
addingData(goodsOrservices, price, today, expenseType)
if __name__ == "__main__":
main()
error:
Traceback (most recent call last):
File "C:\Users\General\Desktop\Codes\Python\Programs\Advanced\ExpenseTracker.py", line 17, in <module>
from matplotlib import pyplot as plt
File "C:\Users\General\Desktop\Codes\Python\venv\Lib\site-packages\matplotlib\__init__.py", line 113, in <module>
from . import _api, _version, cbook, _docstring, rcsetup
File "C:\Users\General\Desktop\Codes\Python\venv\Lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "C:\Users\General\Desktop\Codes\Python\venv\Lib\site-packages\matplotlib\colors.py", line 51, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
pip install was originally corrupted or errored, fresh install after wiping everything worked
I want blend multiple satellite images. but an error occured. I followed the example on the satpy document.
here is code and netcdf file is here : https://drive.google.com/drive/folders/1zp6EBVfjuh41LDRRZo4PJoeGGGn13AKy?usp=sharing
from glob import glob
from satpy import Scene, MultiScene, DataQuery
from satpy.utils import debug_on
debug_on()
areaid = 'worldeqc3km70'
eumetsat = glob('E:/Global/combine_test/MSG4-SEVI-MSG15-0100-NA-20210801000010.306000000Z-20210801001259-4774254.nat')
goes17 = glob('E:/Global/combine_test/OR_ABI-L1b-RadF-M6C13_G17_s20212130000319_e20212130009396_c20212130009445.nc')
gk2a = glob('E:/Global/combine_test/gk2a_ami_le1b_ir105_fd020ge_202108010000.nc')
goes17_scene = Scene(reader="abi_l1b", filenames=goes17)
eumetsat_scene = Scene(reader="seviri_l1b_native", filenames=eumetsat)
gk2a_scene = Scene(reader="ami_l1b", filenames=gk2a)
goes17_scene.load(["C13"])
eumetsat_scene.load(['IR_108'])
gk2a_scene.load(["IR105"])
mscn = MultiScene([goes17_scene, eumetsat_scene, gk2a_scene])
#groups = {DataQuery(name='IR_group', wavelength=(9.8, 10.8, 11.8)): ['C13', 'IR105', 'IR_108']}
groups = {DataQuery(name="IR_group", wavelength=(10, 11, 12)): ['C13', 'IR_108', 'IR105']}
mscn.group(groups)
print(mscn.loaded_dataset_ids)
resampled = mscn.resample(areaid, reduce_data=False)
blended = resampled.blend()
blended.save_datasets(filename='./test_{area}.png'.format(area=areaid))
Error message:
RuntimeError: None of the requested datasets have been generated or could not be loaded. Requested composite inputs may need to have matching dimensions (eg. through resampling).
As mentioned in the comments this is a known bug that will hopefully be fixed in the next couple weeks. Follow issue 2089 for more information.
The short-term workaround is to make your own "blend" method that handles things the way you expect:
from satpy.multiscene import stack
def my_blend(mscn, common_datasets, blend_function=stack):
new_scn = Scene()
for ds_id in common_datasets:
datasets = [scn[ds_id] for scn in mscn.scenes if ds_id in scn]
new_scn[ds_id] = blend_function(datasets)
return new_scn
blended = my_blend(resampled, ["ir_group"])
I am trying to construct a pipeline in Microsoft Azure having (for now) a simple python script in input.
The problem is that I cannot find my output.
In my Notebooks section I have constructed the following two codes:
1) script called "test.ipynb"
# azureml-core of version 1.0.72 or higher is required
from azureml.core import Workspace, Dataset, Datastore
import pandas as pd
import numpy as np
import datetime
import math
#Upload datasets
subscription_id = 'myid'
resource_group = 'myrg'
workspace_name = 'mywn'
workspace = Workspace(subscription_id, resource_group, workspace_name)
dataset_zre = Dataset.get_by_name(workspace, name='file1')
dataset_SLA = Dataset.get_by_name(workspace, name='file2')
df_zre = dataset_zre.to_pandas_dataframe()
df_SLA = dataset_SLA.to_pandas_dataframe()
result = pd.concat([df_SLA,df_zre], sort=True)
result.to_csv(path_or_buf="/mnt/azmnt/code/Users/aniello.spiezia/outputs/output.csv",index=False)
def_data_store = workspace.get_default_datastore()
def_data_store.upload(src_dir = '/mnt/azmnt/code/Users/aniello.spiezia/outputs', target_path = '/mnt/azmnt/code/Users/aniello.spiezia/outputs', overwrite = True)
print("\nFinished!")
#End of the file
2) pipeline code called "pipeline.ipynb"
import os
import pandas as pd
import json
import azureml.core
from azureml.core import Workspace, Run, Experiment, Datastore
from azureml.core.compute import AmlCompute
from azureml.core.compute import ComputeTarget
from azureml.core.runconfig import CondaDependencies, RunConfiguration
from azureml.core.runconfig import DEFAULT_CPU_IMAGE
from azureml.telemetry import set_diagnostics_collection
from azureml.pipeline.steps import PythonScriptStep
from azureml.pipeline.core import Pipeline, PipelineData, StepSequence
print("SDK Version:", azureml.core.VERSION)
###############################
ws = Workspace.from_config()
print('Workspace name: ' + ws.name,
'Subscription id: ' + ws.subscription_id,
'Resource group: ' + ws.resource_group, sep = '\n')
experiment_name = 'aml-pipeline-cicd' # choose a name for experiment
project_folder = '.' # project folder
experiment = Experiment(ws, experiment_name)
print("Location:", ws.location)
set_diagnostics_collection(send_diagnostics=True)
###############################
cd = CondaDependencies.create(pip_packages=["azureml-sdk==1.0.17", "azureml-train-automl==1.0.17", "pyculiarity", "pytictoc", "cryptography==2.5", "pandas"])
amlcompute_run_config = RunConfiguration(framework = "python", conda_dependencies = cd)
amlcompute_run_config.environment.docker.enabled = False
amlcompute_run_config.environment.docker.base_image = DEFAULT_CPU_IMAGE
amlcompute_run_config.environment.spark.precache_packages = False
###############################
aml_compute_target = "aml-compute"
try:
aml_compute = AmlCompute(ws, aml_compute_target)
print("found existing compute target.")
except:
print("creating new compute target")
provisioning_config = AmlCompute.provisioning_configuration(vm_size = "STANDARD_D2_V2",
idle_seconds_before_scaledown=1800,
min_nodes = 0,
max_nodes = 4)
aml_compute = ComputeTarget.create(ws, aml_compute_target, provisioning_config)
aml_compute.wait_for_completion(show_output=True, min_node_count=None, timeout_in_minutes=20)
print("Azure Machine Learning Compute attached")
###############################
def_data_store = ws.get_default_datastore()
def_blob_store = Datastore(ws, "workspaceblobstore")
print("Blobstore's name: {}".format(def_blob_store.name))
# Naming the intermediate data as anomaly data and assigning it to a variable
output_data = PipelineData("output_data", datastore = def_blob_store)
print("output_data object created")
step = PythonScriptStep(name = "test",
script_name = "test.ipynb",
compute_target = aml_compute,
source_directory = project_folder,
allow_reuse = True,
runconfig = amlcompute_run_config)
print("Step created.")
###############################
steps = [step]
print("Step lists created")
pipeline = Pipeline(workspace = ws, steps = steps)
print ("Pipeline is built")
pipeline.validate()
print("Pipeline validation complete")
pipeline_run = experiment.submit(pipeline)
print("Pipeline is submitted for execution")
pipeline_run.wait_for_completion(show_output = False)
print("Pipeline run completed")
###############################
def_data_store.download(target_path = '.',
prefix = 'outputs',
show_progress = True,
overwrite = True)
model_fname = 'output.csv'
model_path = os.path.join("outputs", model_fname)
pipeline_run.upload_file(name = model_path, path_or_stream = model_path)
print('Uploaded the model {} to experiment {}'.format(model_fname, pipeline_run.experiment.name))
And this give me the following error:
Pipeline run completed
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-22-a8a523969bb3> in <module>
111
112 # Upload the model file explicitly into artifacts (for CI/CD)
--> 113 pipeline_run.upload_file(name = model_path, path_or_stream = model_path)
114 print('Uploaded the model {} to experiment {}'.format(model_fname, pipeline_run.experiment.name))
115
/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/core/run.py in wrapped(self, *args, **kwargs)
47 "therefore, the {} cannot upload files, or log file backed metrics.".format(
48 self, self.__class__.__name__))
---> 49 return func(self, *args, **kwargs)
50 return wrapped
51
/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/core/run.py in upload_file(self, name, path_or_stream)
1749 :rtype: azure.storage.blob.models.ResourceProperties
1750 """
-> 1751 return self._client.artifacts.upload_artifact(path_or_stream, RUN_ORIGIN, self._container, name)
1752
1753 #_check_for_data_container_id
/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/_restclient/artifacts_client.py in upload_artifact(self, artifact, *args, **kwargs)
108 if isinstance(artifact, str):
109 self._logger.debug("Uploading path artifact")
--> 110 return self.upload_artifact_from_path(artifact, *args, **kwargs)
111 elif isinstance(artifact, IOBase):
112 self._logger.debug("Uploading io artifact")
/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/_restclient/artifacts_client.py in upload_artifact_from_path(self, path, *args, **kwargs)
100 path = os.path.normpath(path)
101 path = os.path.abspath(path)
--> 102 with open(path, "rb") as stream:
103 return self.upload_artifact_from_stream(stream, *args, **kwargs)
104
FileNotFoundError: [Errno 2] No such file or directory: '/mnt/azmnt/code/Users/aniello.spiezia/outputs/output.csv'
Do you know what the problem could be?
In particular I am interested in saving somewhere the output file called "output.csv"
The best way for you to do this depends a bit on how you want to process the output.csv file after the run completed. But, in general you can just write your csv to the ./outputs folder:
# azureml-core of version 1.0.72 or higher is required
from azureml.core import Workspace, Dataset, Datastore
import pandas as pd
import numpy as np
import datetime
import math
#Upload datasets
subscription_id = 'myid'
resource_group = 'myrg'
workspace_name = 'mywn'
workspace = Workspace(subscription_id, resource_group, workspace_name)
dataset_zre = Dataset.get_by_name(workspace, name='file1')
dataset_SLA = Dataset.get_by_name(workspace, name='file2')
df_zre = dataset_zre.to_pandas_dataframe()
df_SLA = dataset_SLA.to_pandas_dataframe()
result = pd.concat([df_SLA,df_zre], sort=True)
if not os.path.isdir('outputs')
os.mkdir('outputs')
result.to_csv('outputs/output.csv', index=False)
print("\nFinished!")
#End of the file
After the run has completed, AzureML will upload the contents of the outputs directory to the run history, so no need to datastore.upload().
Afterwards, you can see the file in http://ml.azure.com when you navigate to the run like my model.pt file below:
See here for some information on the ./outputs and ./logs folders: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-save-write-experiment-files#where-to-write-files
If you actually want to create another DataSet as a result of your Run, please see this post here: Azure Machine Learning Service - dataset API question
In Daniel's example above, you would need to download the output from the run rather than the datastore in your pipeline.ipynb code. Instead of calling def_data_store.download(), you would call pipeline_run.download('outputs/output.csv', '.').
Another option is to output your data using PipelineData. PipelineData represents a named piece of output of a pipeline step, and is useful if you want to connect multiple steps together with inputs and outputs. With PipelineData, you would need to pass the PipelineData object into PythonScriptStep when you declare your step (as part of arguments=[] and outputs=[]), and then have your script read the output path from the command-line arguments.
This notebook has examples of using PipelineData within a pipeline and downloading the outputs: https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-data-dependency-steps.ipynb
And this blog post has details about how to handle this within your script (parsing the command-line arguments, creating the output directory, and writing the output file): https://blog.x5ff.xyz/blog/ai-azureml-python-data-pipelines/
I am making a project with a GUI for liver ultrasound diagnostics.
I use PyQT5 (5.12.1) for GUI and sklearn (0.21.2) for statistics models. Main texture features I get from pyradiomics (2.2.0).
When I compile my project in PyCharm 2019.1 - all works completely fine.
But when I try to build my project as .exe file with pyinstaller, I got some erors. I solved most of them (about missing libraries) but this one left.
I got errors:
Feature class firstorder is not recognized
Feature class glcm is not recognized
Feature class glrlm is not recognized
Feature class ngtdm is not recognized
Feature class glszm is not recognized
and my model also gives an error (when I fit my new data with models that were already saved in .sav files from sklearn):
ValueEror: operands could not be broadcast together with shapes (1,3)(96,)(1,3)
1) I tried to change from:
extractor.enableFeatureClassByName('glcm')
to:
extractor.enableFeatureClassByName(str('glcm'))
It did not help.
2) Also I tried to build a project at different versions of pyradiomics:
2.1.1 and
2.2.0
give the same result (error)
import pandas as pd
import numpy as np
import pickle
import sklearn
...
folderName = "tmp"
sl = "/"
image_path_to = os.getcwd() + "/data/nrrd/" + folderName + sl + name_image
label_path_to = os.getcwd() + "/data/nrrd/" + folderName + sl + name_label
# Instantiate the extractor
extractor = featureextractor.RadiomicsFeatureExtractor()
# Switch on only needed feature class
extractor.disableAllFeatures()
extractor.enableFeatureClassByName('firstorder') <<< There is a problem
extractor.enableFeatureClassByName('glcm')
extractor.enableFeatureClassByName('glrlm')
extractor.enableFeatureClassByName('ngtdm')
extractor.enableFeatureClassByName('gldm')
extractor.enableFeatureClassByName('glszm')
# result -> ordered dict
result = extractor.execute(image_path_to, label_path_to)
df = pd.DataFrame(result, index=[0])
...
# Load the model from disk
model_name = 'Multi-layer Perceptron'
poolParam = ["diagnosis_code", "isnorm"]
models = [0,5]
for param in poolParam:
filename = 'data/result/model/' + model_name + ' ' + param + '.sav'
file = open(filename, 'rb')
loaded = pickle.load(file)
print("Model <" + model_name + " " + param + "> was loaded")
# Test the classifier
y_pred = int(loaded.predict(data)) <<< There is a problem
I am trying to create a face recognition software using OpenCV, but the code I found in the library is made in Python 2. Is there a Python 3 version of this?
Here's the link: https://github.com/thecodacus/Face-Recognition
I already have a folder for dataset and trainer.
import cv2
import numpy as np
from PIL import Image
import os
# Path for face image database
path = 'dataset'
recognizer = cv2.face.LBPHFaceRecognizer_create()
detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml");
# function to get the images and label data
def getImagesAndLabels(path):
imagePaths = [os.path.join(path,f) for f in os.listdir(path)]
faceSamples=[]
ids = []
for imagePath in imagePaths:
PIL_img = Image.open(imagePath).convert('L') # convert it to grayscale
img_numpy = np.array(PIL_img,'uint8')
id = int(os.path.split(imagePath)[-1].split('.')[1])
faces = detector.detectMultiScale(img_numpy)
for (x,y,w,h) in faces:
faceSamples.append(img_numpy[y:y+h,x:x+w])
ids.append(id)
return faceSamples,ids
print ("\n [INFO] Training faces. It will take a few seconds. Wait ...")
faces,ids = getImagesAndLabels(path)
recognizer.train(faces, np.array(ids))
# Save the model into trainer/trainer.yml
recognizer.write('trainer/trainer.yml') # recognizer.save() worked on Mac, but not on Pi
# Print the numer of faces trained and end program
print("\n [INFO] {0} faces trained. Exiting Program".format(len(np.unique(ids))))
Error:
Traceback (most recent call last):
File "/Users/user/Desktop/FacialRecognition/02_face_training.py", line 46, in <module>
faces,ids = getImagesAndLabels(path)
File "/Users/user/Desktop/FacialRecognition/02_face_training.py", line 36, in getImagesAndLabels
id = int(os.path.split(imagePath)[-1].split('.')[1])
ValueError: invalid literal for int() with base 10: 'User'
On that repository there's a dataSet directory, with a file named like:
In [665]: name='Face-Recognition/dataSet/face-1.1.jpg'
Applied to that name, your code sample does:
In [668]: os.path.split(name)
Out[668]: ('Face-Recognition/dataSet', 'face-1.1.jpg')
In [669]: os.path.split(name)[-1]
Out[669]: 'face-1.1.jpg'
In [670]: os.path.split(name)[-1].split('.')
Out[670]: ['face-1', '1', 'jpg']
In [671]: os.path.split(name)[-1].split('.')[1]
Out[671]: '1'
In [672]: int(os.path.split(name)[-1].split('.')[1])
Out[672]: 1
Apparently your file has a different name format, one that includes 'User' in a slot where this code expects a number.
You need to correct the file name, or change this parsing code.
The image name which you got in the dataset are as User.*somename*, so remove User from all the image names.
try to change format images is 'face.1.1.jpg'
then you can split the dot with this code
faceID = int(os.path.split(imagePath)[-1].split(".")[2])
This did the job for me:
Id=int(os.path.split(imagePath)[-1].split(".")[0])