Social-Evolution-and-Behavior / anTraX

anTraX: high throughput tracking of color-tagged insects
https://antrax.readthedocs.io/
GNU General Public License v3.0
17 stars 3 forks source link

Problems with using command train #35

Open Sean-Nolan6 opened 2 years ago

Sean-Nolan6 commented 2 years ago

Hi I am currently setting up Antrax on an Ubuntu 21.10. I am using conda as a virtual environment and have installed the Matlab python engine that came with Matlab R2019a. The issue I currently am having is that when using the command antrax train I am seeing an error of:

Traceback (most recent call last):
  File "/home/sean/anaconda3/envs/test/bin/antrax", line 8, in <module>
    sys.exit(main())
  File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/antrax/cli.py", line 659, in main
    """)
  File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/sigtools/modifiers.py", line 158, in __call__
    return self.func(*args, **kwargs)
  File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/clize/runner.py", line 363, in run
    ret = cli(*args)
  File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/clize/runner.py", line 220, in __call__
    return func(*posargs, **kwargs)
  File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/clize/runner.py", line 262, in _cli
    return func('{0} {1}'.format(name, command), *args)
  File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/clize/runner.py", line 220, in __call__
    return func(*posargs, **kwargs)
  File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/antrax/cli.py", line 447, in train
    c.train(examplesdir, ne=ne, aug_options=aug_options)
  File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/antrax/classifier.py", line 513, in train
    cw = class_weight.compute_class_weight('balanced', np.unique(FL.classes), FL.classes)
TypeError: compute_class_weight() takes 1 positional argument but 3 were given

It seems to be an error regarding the Matlab python engine version however I am using Matlab R2019a and pip list shows I have matlabengineforpython R2018a installed. Any help fixing this would be appreciated.

asafgal commented 2 years ago

Hey Sean, This is a python error, not related to the matlab engine. Can you try this fix:

In the file anTraX/antrax/classifier.py, change line 513 to:

cw = class_weight.compute_class_weight(class_weight='balanced', classes =np.unique(FL.classes), y=FL.classes)

Then update the python code with pip install -e . I am unable to test this myself currently, so let me know what happens!

Sean-Nolan6 commented 2 years ago

Hi your first solution helped the first issue, but I'm currently trialing your other datasets to get a sense of how long my tests were. However when I try and run train on the V25 sample, it keeps coming up with the same error:

Epoch 1/3 124/1000 [==>...........................] - ETA: 5:54 - loss: 3.5632 - acc: 0.3478Traceback (most recent call last): File "/home/sean/anaconda3/envs/test/bin/antrax", line 33, in sys.exit(load_entry_point('antrax', 'console_scripts', 'antrax')()) File "/home/sean/Documents/AntTrax/anTraX/antrax/cli.py", line 659, in main """) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/sigtools/modifiers.py", line 158, in call return self.func(*args, kwargs) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/clize/runner.py", line 363, in run ret = cli(args) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/clize/runner.py", line 220, in call return func(posargs, kwargs) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/clize/runner.py", line 262, in _cli return func('{0} {1}'.format(name, command), args) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/clize/runner.py", line 220, in call return func(posargs, kwargs) File "/home/sean/Documents/AntTrax/anTraX/antrax/cli.py", line 447, in train c.train(examplesdir, ne=ne, aug_options=aug_options) File "/home/sean/Documents/AntTrax/anTraX/antrax/classifier.py", line 533, in train verbose=verbose) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 1296, in fit_generator steps_name='steps_per_epoch') File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_generator.py", line 221, in model_iteration batch_data = _get_next_batch(generator) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_generator.py", line 363, in _get_next_batch generator_output = next(generator) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/data_utils.py", line 789, in get six.reraise(sys.exc_info()) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/six.py", line 719, in reraise raise value File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/data_utils.py", line 783, in get inputs = self.queue.get(block=True).get() File "/home/sean/anaconda3/envs/test/lib/python3.7/multiprocessing/pool.py", line 657, in get raise self._value File "/home/sean/anaconda3/envs/test/lib/python3.7/multiprocessing/pool.py", line 121, in worker result = (True, func(args, kwds)) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/data_utils.py", line 571, in get_index return _SHARED_SEQUENCES[uid][i] File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/keras_preprocessing/image/iterator.py", line 65, in getitem return self._get_batches_of_transformed_samples(index_array) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/keras_preprocessing/image/iterator.py", line 230, in _get_batches_of_transformed_samples interpolation=self.interpolation) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/keras_preprocessing/image/utils.py", line 114, in load_img img = pil_image.open(io.BytesIO(f.read())) File "/home/sean/anaconda3/envs/test/lib/python3.7/site-packages/PIL/Image.py", line 3009, in open "cannot identify image file %r" % (filename if filename else fp) PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f37b8629470>

asafgal commented 2 years ago

Both errors are due to compatibility issue with 3rd party packages. To fix your last error, reinstall the pillow package:

pip uninstall pillow
pip install pillow==8.4.0

Thanks for bringing this to my attention, I will update the requirement file accordingly.

Sean-Nolan6 commented 2 years ago

Uninstalling and installing pillow doesn't seem to have fixed the issue, any other ideas to what it might be?

asafgal commented 2 years ago

Can you verify the pillow version? In a python console:

import PIL
print(PIL.__version__)
Sean-Nolan6 commented 2 years ago

This is the error I get: (test) sean@seans-ants:~$ import PIL Traceback (most recent call last): File "/usr/lib/command-not-found", line 28, in from CommandNotFound import CommandNotFound File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in from CommandNotFound.db.db import SqliteDatabase File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in import apt_pkg ImportError: /usr/local/MATLAB/MATLAB_Runtime/v96/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /lib/x86_64-linux-gnu/libapt-pkg.so.6.0)

asafgal commented 2 years ago

The command I sent you are python command that need to be run inside a python interactive shell (open one by typing “python” while inside your antrax conda environment).

On 23 Feb 2022, at 22:14, Sean-Nolan6 @.***> wrote:

This is the error I get: (test) @.***:~$ import PIL Traceback (most recent call last): File "/usr/lib/command-not-found", line 28, in from CommandNotFound import CommandNotFound File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in from CommandNotFound.db.db import SqliteDatabase File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in import apt_pkg ImportError: /usr/local/MATLAB/MATLAB_Runtime/v96/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /lib/x86_64-linux-gnu/libapt-pkg.so.6.0)

— Reply to this email directly, view it on GitHub https://github.com/Social-Evolution-and-Behavior/anTraX/issues/35#issuecomment-1049174138, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACERP5VPDS74BUENN6UVWPTU4U53NANCNFSM5LYZGGHA. You are receiving this because you commented.