-1

In one of datascience web app project, I designed an app to predict the type of plant disease. It contains onnx models. The prediction runs without an error standalone. But inside the streamlit code, it raises an error:

UFuncTypeError: ufunc 'subtract' did not contain a loop with signature matching types (dtype('<U23'), dtype('float32')) -> None**

Did someone come across this kind of a situation?

enter image description here

This is the link to the project files: https://drive.google.com/drive/folders/1TVn9zRaJsoMUPz_6puaWk11LFkpvIyyl?usp=sharing (to run the project, after installing dependancies, run streamlit run webapp_plant_dis_clas.py, for now only model for the tomato exists. so only select it inside the web app to make a prediction.)

vvvvv
  • 25,404
  • 19
  • 49
  • 81
tad
  • 117
  • 7

1 Answers1

0

This has nothing to do with streamlit.

Use the following to fix your issue.

prediction = pred_out(img, model_selector, plant_model_dictionary)[0]

and this to get the max index.

print(prediction.argmax(axis=0))  # 6

Output Prediction

[2.8063682e-14 3.1059124e-05 5.7825161e-11 8.3977110e-09 2.5989549e-13
 1.2324781e-04 9.9980527e-01 7.5968347e-17 4.0455303e-05 3.2742336e-09]

Streamlit run

enter image description here

Code

if conf is True: #predict button is pressed, you need a way of identifying is it pressed or not
    # prediction - pred_out(img, model_selector, plant_model_dictionary)[0]
    prediction = pred_out(img, model_selector, plant_model_dictionary)[0]
    st.write(f'prediction: {prediction}')
    # max_ind = np.where(prediction==max)[0][0]
    # print(max_ind)
    st.write(f'prediction max index: {prediction.argmax(axis=0)}')
ferdy
  • 4,396
  • 2
  • 4
  • 16
  • tried it man. It didn't work. It says the error is in the line pred = sess.run([output_name], {input_name: img_})[0] inside the function pred_out. of course running the neural network without streamlit framework did not threw any error. – tad Apr 03 '22 at 13:32
  • I modify my answer showing the streamlit output. It runs fine on my PC. – ferdy Apr 03 '22 at 13:48
  • It seems you have successfully run it. I'm still stuck in that error. – tad Apr 03 '22 at 13:52
  • What's the new error message after fixing `prediction = pred_out(img, model_selector, plant_model_dictionary)[0]`? – ferdy Apr 03 '22 at 13:53
  • Ahh sorry, I'm very sorry. I have just typed - instead of =. Sorry for wasting your time. Truly appriciate your help. – tad Apr 03 '22 at 13:57