plant-train
hi , i saw that you posted a tutorial on how to use the plantcv-train.py file in issue #206 , but when i click on it it says that the file has been deleted , can you share it again?
Hi @ryaddenni,
I am not able to find that document anymore for some reason.
For using the plantcv-train.py naive_bayes_multiclass program, we need to create a table of RGB color values for each category we want to label (minimum of 2, one foreground and one background).
There are other ways but we generally use the ImageJ Pixel Inspector tool. It allows you to extract RGB color values from a region of an image by clicking on a pixel (you can choose how many neighboring pixels to include). When you click on a point it will bring up a window with a matrix of pixels and the RGB values, and these can be copied to your clipboard.
Then in a plain text file, add a header for each category and paste the block of RGB values under each header. An example with two categories is here: https://github.com/danforthcenter/plantcv/blob/master/tests/testdata/pixel_inspector_rgb_values.txt. There's no need to have the same number of RGB values for each category, you just want a good sample of the variety of colors for each category.
This file containing the blocks of color values needs to be converted into a table. This is done by running the program plantcv-utils.py tabulate_bayes_classes, which takes the input file above and outputs a new text file with the RGB values and categories as a table.
Then to train the classifier, run plantcv-train.py naive_bayes_multiclass with the table as the input file, an output text file for the Probability Density Functions, and optionally with plots of the PDFs for hue, saturation, and value color properties.
The PDFs file is then used in the classifier function to segment an image. There's an example tutorial here: https://plantcv.readthedocs.io/en/stable/tutorials/machine_learning_tutorial/
Often the segmentation can be improved, requiring going back to ImageJ to collect additional samples, adding them to the first text file, recreating the table, and rerunning the training step.
hi , i ran this command : python-m plantcv-train naive_bayes_multiclass -f pixels.txt -o PDFs.txt --plots
and here is what i get :
Starting run 2022-07-26_13:37:12
Running the naive Bayes multiclass training method...
Traceback (most recent call last):
File "C:\Users\click\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None,"__main__", mod_spec)
File "C:\Users\click\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals)
File "C:\Users\click\Documents\plant--00\plantcv-train.py", line 91, in main()
File "C:\Users\click\Documents\plant--00\plantcv-train.py", line 86, in main options()
File "C:\Users\click\Documents\plant--00\plantcv-train.py", line 54, in options args.func(args)
File "C:\Users\click\Documents\plant--00\plantcv-train.py", line 76, in run_naive_bayes_multiclass plantcv.learn.naive_bayes_multiclass(samples_file=args.file, outfile=args.outfile, mkplots=args.plots) AttributeError: module 'plantcv.plantcv' has no attribute 'learn'
Hi @ryaddenni,
At the end of the error it's saying it can't import part of PlantCV. This suggests that it is not installed or available in your environment. Can you confirm that you can import it?
If you start a python console on the command line and run:
from plantcv import plantcv as pcv
print(pcv.__version__)
print(pcv.__file__)
This will return the version and installed location of PlantCV.
hi , i've managed to fix the import statement and now i'm getting this : Starting run 2022-07-27_21:57:01
Running the naive Bayes multiclass training method...
Traceback (most recent call last):
File
"C:\Users\click\AppData\Local\Programs\Python\Python310\lib\runpy.py", line
196, in _run_module_as_main
return _run_code(code, main_globals, None,"main", mod_spec)
File
"C:\Users\click\AppData\Local\Programs\Python\Python310\lib\runpy.py", line
86, in _run_code
exec(code, run_globals)
File "C:\Users\click\Documents\plant--00\plantcv-train.py", line 92, in
Le mer. 27 juil. 2022 à 04:12, Noah Fahlgren @.***> a écrit :
Hi @ryaddenni https://github.com/ryaddenni,
At the end of the error it's saying it can't import part of PlantCV. This suggests that it is not installed or available in your environment. Can you confirm that you can import it?
If you start a python console on the command line and run:
from plantcv import plantcv as pcv print(pcv.version)print(pcv.file)
This will return the version and installed location of PlantCV.
— Reply to this email directly, view it on GitHub https://github.com/danforthcenter/plantcv/issues/921#issuecomment-1196216546, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU2T4HRRJHWXP5YJOWUR5T3VWCSKFANCNFSM53XM5KJQ . You are receiving this because you were mentioned.Message ID: @.***>
hi , i've managed to fix the import statement and now i'm getting this : Starting run 2022-07-27_21:57:01
Running the naive Bayes multiclass training method...
Traceback (most recent call last):
File
"C:\Users\click\AppData\Local\Programs\Python\Python310\lib\runpy.py", line
196, in _run_module_as_main
return _run_code(code, main_globals, None,"main", mod_spec)
File
"C:\Users\click\AppData\Local\Programs\Python\Python310\lib\runpy.py", line
86, in _run_code
exec(code, run_globals)
File "C:\Users\click\Documents\plant--00\plantcv-train.py", line 92, in
by the way does the script work for you? is it just me? i checked the issues on github and never found anything similar to the errors i keep getting
Le mer. 27 juil. 2022 à 04:12, Noah Fahlgren @.***> a écrit :
Hi @ryaddenni https://github.com/ryaddenni,
At the end of the error it's saying it can't import part of PlantCV. This suggests that it is not installed or available in your environment. Can you confirm that you can import it?
If you start a python console on the command line and run:
from plantcv import plantcv as pcv print(pcv.version)print(pcv.file)
This will return the version and installed location of PlantCV.
— Reply to this email directly, view it on GitHub https://github.com/danforthcenter/plantcv/issues/921#issuecomment-1196216546, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU2T4HRRJHWXP5YJOWUR5T3VWCSKFANCNFSM53XM5KJQ . You are receiving this because you were mentioned.Message ID: @.***>
That error occurs when there is a formatting error in the input pixel values table. Each row of the table has to have the same number of columns, even if the columns are blank. And for a row cell that is not blank it needs to have a full RGB triplet (comma-delimited)
Feel free to post your text file here if you do not see a formatting issue and we can help look it over
thank you so much it worked !!! it was a problem with the pixel file one last thing i need to run this on many images do you know any other tool than imagej to collect the pixels ? because collecting them manually and pasting them to a file is super slow
Le mer. 27 juil. 2022 à 22:03, Noah Fahlgren @.***> a écrit :
That error occurs when there is a formatting error in the input pixel values table. Each row of the table has to have the same number of columns, even if the columns are blank. And for a row cell that is not blank it needs to have a full RGB triplet (comma-delimited)
Feel free to post your text file here if you do not see a formatting issue and we can help look it over
— Reply to this email directly, view it on GitHub https://github.com/danforthcenter/plantcv/issues/921#issuecomment-1197365659, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU2T4HXNNICGUPPZRX3E7M3VWGP3NANCNFSM53XM5KJQ . You are receiving this because you were mentioned.Message ID: @.***>
Hi @ryaddenni,
Typically you would not collect training data for all of the images in your dataset, just one or more relevant sample images. As long as there is consistency among the images in your dataset, the model trained on a relatively small training set should perform well across the rest of the dataset. This limits the amount of time you need to spend in ImageJ and/or doing training
@nfahlgren I followed the tips and the conversation above. But I am not able to run plantcv-train.py naive_bayes_multiclass I am using Jupiter and the first thing I checked my version and the installed location of PlantCV. 3.14.1
I have used the Pixel Inspector tool and created my text file as recommended as well.
What is the code to run plantcv-train.py naive_bayes_multiclass ?
Many thanks Rafael
Hi @rgtava, when you say you are using Jupyter, do you mean a notebook or the Jupyter Terminal interface? I ask because plantcv-train.py naive_bayes_multiclass is a command-line program, so you would need to run it in the terminal with the plantcv environment activated.
Hi @nfahlgren many thanks for your prompt reply. I am using Jupyter notebook. I would like to measure the GFP signals of Arabidopsis plants infected with virus or mock under UV light. I am stuck in this training step. Could you please guide me on this part? Many thanks! Cheers
Hi @rgtava, could you upload an example image? My intuition is that the naive Bayes method may not be the best approach because the color images are not going to be typical in your use case, they are likely heavy signal in the red and green channels and low in the blue channel. One suggestion is to try using pcv.visualize.colorspaces to see if one of the grayscale channels from HSV or LAB separates the signal you are trying to detect well, then you can use a simpler thresholding approach