Skip to content

Command line tools#825

Merged
subdavis merged 12 commits intomainfrom
command-line-tools
Jul 30, 2021
Merged

Command line tools#825
subdavis merged 12 commits intomainfrom
command-line-tools

Conversation

@subdavis
Copy link
Contributor

@subdavis subdavis commented Jun 30, 2021

  • Adds coco and viame to dive conversion
  • Adds dataset generation
  • Adds DIVE json file verification against pydantic schema.

@BryonLewis
Copy link
Collaborator

I don't know if you want this updated version of generateLargeDatasey.py, No guarantees on functionality but it allows for creation of videos as well, and I now modified the image/video so they have some noise to display. I used this to generate data for the long loading PR testing.

https://gist.github.com/BryonLewis/ac74e93f954eba591ed76cd84c954be4

Updates:

  • --video option to indicate you want a video
  • --width/--height options to specify size of image or size of video, all bboxes are still full frame though
  • --fps indicator for video framerate.

@subdavis
Copy link
Contributor Author

This is probably going to go stale for a while, I'll deal with updating it later.

@subdavis subdavis force-pushed the command-line-tools branch from 2d79301 to b797d3b Compare July 8, 2021 19:04
@subdavis subdavis marked this pull request as ready for review July 8, 2021 20:57
@subdavis subdavis requested review from BryonLewis and f4str and removed request for f4str July 8, 2021 20:57
click.echo(f'wrote attrib {output_attrs.name}')


@convert.command(name="viame2dive")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also be nice to also add a dive2viame command since the export csv serializer already exists.

import cv2
import numpy as np
from PIL import Image
from tqdm import tqdm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy and tqdm should probably also be added to the dev requirements.


from dive_server.serializers import kwcoco, viame
from dive_utils import models
from scripts import generateLargeDataset
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateLargeDataset imports numpy, opencv, and tqdm and since cli.py imports generateLargeDataset, it also require those imports. This isn't an issue if the dev requirements are installed, but if the user wants to use the CLI, they would need the dev requirements.

server/setup.py Outdated
version="1.4.1",
zip_safe=False,
entry_points={
"console_scripts": ["dive=scripts.cli:cli"],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably update the README with a really brief section that the CLI exists and how to use it.

@subdavis subdavis self-assigned this Jul 15, 2021
@subdavis subdavis force-pushed the command-line-tools branch from cf702e2 to 6b649c8 Compare July 21, 2021 16:37
@subdavis
Copy link
Contributor Author

subdavis commented Jul 21, 2021

Updated changes:

  • drop notebooks completely.
  • move serializers to dive_utils to prevent the command line from depending on the dive_server package (and because I think this is the correct place to put it anyway)
  • Add dev and normal command lines, so that we can build a standalone that doesn't require cv2 and numpy

@subdavis subdavis requested review from BryonLewis and f4str July 21, 2021 16:43
):
os.mkdir(directory)

with click.progressbar(range(int(frames))) as bar:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If frames is already an integer, is there a reason to cast it again?

tracks[track] = track_obj
json_file = f"{directory}/result_test.json"
with open(json_file, "w") as outfile:
json.dump(tracks, outfile)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nitpicking here, but since the other cli converters use indent=4, this should also probably have that to be consistent. Also makes viewing the output json way easier for anyone who uses it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably remove from both, it adds a lot of bytes to the file

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it's probably better to have all json outputs be 1 line and compressed so people's text editors don't crash when opening massive files.

server/setup.py Outdated
"numpy",
"opencv-python",
"pytest",
"pytest-cov",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to add pytest-cov to the dev requirements? It doesn't seem to be used anywhere and if it is needed, tox can just automatically install it.

server/setup.py Outdated
include_package_data=True,
zip_safe=False,
entry_points={
"console_scripts": ["dive=scripts.cli_dev:cli"],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using the dev cli. We should probably have two entry points for console scripts (one for standard and one for dev) like this:

"console_scripts": ["dive=scripts.cli:cli", "dive-dev=scripts.cli_dev:cli"],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason to expose both, IMO. The dev cli includes everything. The limited CLI is just so pyinstaller doesn't bundle numpy

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. In that case, we should probably specify somewhere that the cli requires dev requirements.

server/tox.ini Outdated

[testenv:buildcli]
extra =
dev
Copy link

@f4str f4str Jul 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're packaging the non-dev cli, there's no reason to include the dev requirements. This also brings the question if you should be able to build just one or both the dev and non-dev. tox can probably have a switch flag to choose. Alternatively, we can have two different tox options (buildcli and buildcli_dev).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should only be able to build the non-dev

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Then you can just remove the

extra =
     dev

This won't make a difference in the pyinstaller output, but by doing this tox won't need to install numpy and opencv just to setup the environment (which isn't needed for creating the non-dev cli). No effect on functionality, but will save some time.

server/tox.ini Outdated
deps =
pyinstaller
commands =
pyinstaller --onefile scripts/cli.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to work correctly since the generated output file doesn't have any options other than --help and --version. I'm not sure if this still WIP or actually has a bug. I'm suspecting it might be something to do with the cli.py file not importing stuff correctly for pyinstaller to use in click.

Also be sure to add {posargs} at the end so additional optional flags can be passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to blow away my tox env to reproduce. rm -rf .tox && tox -e buildcli && ./dist/cli . Something I had before was making this work.

pass


import scripts.commands # noqa: E402 F401
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of hacky to import all the click commands and rely on the import registering all the click commands. There are much better ways to separate out the commands and cli files.

The top answer in this stackoverflow post is pretty good:
https://stackoverflow.com/questions/34643620/how-can-i-split-my-click-commands-each-with-a-set-of-sub-commands-into-multipl

But I'd recommend doing something similar to what girder is doing:
https://github.com/girder/girder/tree/master/girder/cli

This also might be the reason why the pyinstaller build doesn't work.

@subdavis subdavis requested a review from f4str July 22, 2021 15:46
@f4str
Copy link

f4str commented Jul 22, 2021

This is great. I was emphasizing the {posargs} in tox so you can specify additional parameters. For example

tox -e buildcli -- --distpath path/to/output --clean --log-level DEBUG

Everything else seems to work great. I ran some tests and validation, conversion, and data generation all work perfectly.

Just a few minor points

  • As mentioned before, we should decide whether to remove the indent=4 from the viame2dive and coco2dive so the files don't get bloated
  • I noticed running
    dive --version
    doesn't seem to work and crashes. Looks like click can't figure out the package distribution correctly for the server/scripts directory or something. Probably doesn't matter too much, but the work around is really simple. In server/scripts/__init__.py make the replacement
    @click.version_option(1.0)
    to manually pass in a version number.
  • sever/testutils is pretty much empty except for 2 json files which are only used in unit tests. One option is to just move them to server/tests, but this isn't that big of an issue.

@f4str
Copy link

f4str commented Jul 22, 2021

Update on the --version flag issue. Much simpler fix. According to https://click.palletsprojects.com/en/8.0.x/api/#click.version_option just specify the python package name

@click.group()
@click.version_option(package_name='dive_server')
def cli():
    pass

If you don't want the version number being displayed at all, add the message parameter. Source: https://github.com/girder/girder/blob/master/girder/cli/__init__.py

@click.group()
@click.version_option(package_name='dive_server', message='%(package)s')
def cli():
    pass

@subdavis
Copy link
Contributor Author

@f4str I addressed those comments.

  • indent=4 was kept for the attributes files and removed for the track files. The attributes files will always be small.
  • testutils should just be json files now

Copy link

@f4str f4str left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Tested it out (including --version) and everything runs without issue).

@subdavis
Copy link
Contributor Author

@BryonLewis would you like to review again?

@subdavis subdavis merged commit 5375ec4 into main Jul 30, 2021
@subdavis subdavis deleted the command-line-tools branch July 30, 2021 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants