danforthcenter / plantcv

Plant phenotyping with image analysis
Mozilla Public License 2.0
665 stars 265 forks source link

Syntax Error when trying to run plantcv-train #1590

Closed ryanskiba closed 2 months ago

ryanskiba commented 2 months ago

Describe the bug When I attempt to create a PDF using "plantcv-train" I get a syntax error that just tells me my syntax is invalid.

To Reproduce The code I ran: import numpy as np import argparse import os import sys import cv2 from matplotlib import pyplot as plt import pandas as pd print("All modules loaded")

%matplotlib widget from plantcv import plantcv as pcv from plantcv.parallel import WorkflowInputs

plantcv-train naive_bayes_multiclass --file pixelinspectdata.txt --outfile naive_bayes_pdfs.txt --plots

Cell In[3], line 1 plantcv-train naive_bayes_multiclass --file pixelinspectdata.txt --outfile naive_bayes_pdfs.txt --plots ^ SyntaxError: invalid syntax

Expected behavior naive_bayes_pdfs.txt is output.

Local environment (please complete the following information):

Additional context I made sure the tab-delimited .txt file was in the active directory. In the same notebook I have been cropping and color-correcting images using plantcv without issue. I haven't been able to find a tutorial on using plantcv-train like there is for color correcting and cropping.

HaleySchuhl commented 2 months ago

@ryanskiba ^^ fully agree. I just reported that comment to GitHub Support. Sorry about that!

Thanks for opening this issue. It looks like you are using the Command Line Interface syntax correctly but in a jupyter notebook possibly? Please refer to our Naive Bayes Tutorial for more detail than the ReadTheDocs page, and let us know if this is still not resolved. Thanks.

ryanskiba commented 2 months ago

@HaleySchuhl Yes, I'm using it in a jupyter notebook. Is there a better way to do it? And I copied the code straight from that link, but I wish there was a Binder or something where I could see the script in action. Thanks!

nfahlgren commented 2 months ago

I think you can add an exclaimation point in front of the command to run it in Jupyter.

!plantcv-train naive_bayes_multiclass --file pixelinspectdata.txt --outfile naive_bayes_pdfs.txt --plots
ryanskiba commented 2 months ago

I get this output after adding the exclamation point.

'plantcv-train' is not recognized as an internal or external command, operable program or batch file.

k034b363 commented 2 months ago

You could also try the notebook version of the command: plantcv.learn.naive_bayes_multiclass(input, output) This has worked for me within a Jupyter notebook.

ryanskiba commented 2 months ago

@k034b363 After trying that I get "NameError: name 'plantcv' is not defined"

k034b363 commented 2 months ago

I think that's because you have imported plantcv as pcv, so it would actually be: pcv.learn.naive_bayes_multiclass(input, output)

ryanskiba commented 2 months ago

Failed again...


AttributeError Traceback (most recent call last) Cell In[6], line 1 ----> 1 pcv.learn.naive_bayes_multiclass(pixelinspectdata.txt, naive_bayes_pdfs.txt)

AttributeError: module 'plantcv.plantcv' has no attribute 'learn'

k034b363 commented 2 months ago

Oops, sorry, that's my bad, you actually have to add an import: from plantcv import learn and then the command is just: learn.naive_bayes_multiclass(pixelinspectdata.txt, naive_bayes_pdfs.txt).

k034b363 commented 2 months ago

And those in/out files will have to be string paths for the non-command line version, of course.

ryanskiba commented 2 months ago

@k034b363 Thank you so much, that worked! I appreciate all your help!

HaleySchuhl commented 2 months ago

Thanks again for opening this issue. It seems totally valuable to document this syntax. I will open a new issue to add this to our development to-do list, and will close this issue in the meanwhile. Please feel free to reopen with anything further though!