Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize hflip #148

Closed
wants to merge 89 commits into from
Closed

Optimize hflip #148

wants to merge 89 commits into from

Conversation

Adib234
Copy link
Contributor

@Adib234 Adib234 commented Nov 19, 2021

Summary

  • [X ] I have read CONTRIBUTING.md to understand how to contribute to this repository :)

<Please summarize what you are trying to achieve, what changes you made, and how they acheive the desired result.>
I am trying to speed up horizontally flipping, and what I did is use VidGear to execute an ffmpeg command with the preset of ultrafast.

With my changes in running HFlip tests: 4.724 seconds (tests would complete around 2.5 seconds)
Without my changes in running HFlip tests: 12.534 seconds (tests would complete around 10.5 seconds)

I've run each test with and without my changes five times on fish shell with this command time for i in (seq 5); python -m unittest augly.tests.video_tests.transforms.ffmpeg_test.TransformsVideoUnitTest.test_HFlip;; end

Unit Tests

If your changes touch the audio module, please run all of the audio tests and paste the output here. Likewise for image, text, & video. If your changes could affect behavior in multiple modules, please run the tests for all potentially affected modules. If you are unsure of which modules might be affected by your changes, please just run all the unit tests.

Audio

python -m unittest discover -s augly/tests/audio_tests/ -p "*"

Image

python -m unittest discover -s augly/tests/image_tests/ -p "*_test.py"
# Or `python -m unittest discover -s augly/tests/image_tests/ -p "*.py"` to run pytorch test too (must install `torchvision` to run)

Text

python -m unittest discover -s augly/tests/text_tests/ -p "*"

Video

python -m unittest discover -s augly/tests/video_tests/ -p "*"

All

python -m unittest discover -s augly/tests/ -p "*"

Other testing

If applicable, test your changes and paste the output here. For example, if your changes affect the requirements/installation, then test installing augly in a fresh conda env, then make sure you are able to import augly & run the unit test

Adib234 and others added 30 commits September 29, 2021 18:35
Summary:
Sometimes `extract_audio_to_file()` only extracts the beginning of an audio clip, not the full one. This issue was identified in Adib (MLH intern)'s [PR](facebookresearch#133) adding `augment_audio` because the audio metadata had a src & dst duration way shorter than that of the video.

- Changed the code in `extract_audio_to_file()` to be more like [this example](https://www.kaggle.com/josecarmona/ffmpeg-python-example-to-extract-audio-from-mp4) I found, which seems to work better for wav files
- If the audio file is aac format, run the old version of the function (because the new version isn't compatible with aac)

Differential Revision: D31378945

fbshipit-source-id: 38543c0a774e24800d7dc00032d3c9e48ffaa0c8
@facebook-github-bot
Copy link
Contributor

@Adib234 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@zpapakipos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.


@abstractmethod
def get_command(
self, video_path: str, output_path: Optional[str] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self, video_path: str, output_path: Optional[str] = None
self, video_path: str, output_path: str

@param video_path: the path to the video to be augmented

@param output_path: the path in which the resulting video will be stored.
If not passed in, the original video file will be overwritten
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If not passed in, the original video file will be overwritten

) -> Tuple[FilterableStream, Dict]:
class VideoAugmenterByHFlip(BaseVidgearFFMPEGAugmenter):
def get_command(
self, video_path: str, output_path: Optional[str] = None, **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self, video_path: str, output_path: Optional[str] = None, **kwargs
self, video_path: str, output_path: str = None, **kwargs

@returns: a tuple containing the FFMPEG object with the augmentation
applied and a dictionary with any output arguments as necessary
@param output_path: the path in which the resulting video will be stored.
If not passed in, the original video file will be overwritten
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If not passed in, the original video file will be overwritten

@facebook-github-bot
Copy link
Contributor

@Adib234 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@Adib234 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@Adib234 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@Adib234 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@zpapakipos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

augly/video/augmenters/ffmpeg/base_augmenter.py Outdated Show resolved Hide resolved
augly/video/augmenters/ffmpeg/base_augmenter.py Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
augly/video/augmenters/ffmpeg/base_augmenter.py Outdated Show resolved Hide resolved
@abstractmethod
def get_command(self, video_path: str, output_path: str) -> List[str]:
"""
Constructs the FFMPEG so that VidGear can run it
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Constructs the FFMPEG so that VidGear can run it
Constructs the FFMPEG command for VidGear

augly/video/augmenters/ffmpeg/base_augmenter.py Outdated Show resolved Hide resolved
augly/video/augmenters/ffmpeg/hflip.py Outdated Show resolved Hide resolved
augly/video/functional.py Outdated Show resolved Hide resolved
Co-authored-by: Zoe Papakipos <zpapakipos@users.noreply.github.com>
@facebook-github-bot
Copy link
Contributor

@Adib234 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@zpapakipos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Comment on lines 19 to 20
the augmentation
in a command line
Copy link
Contributor

Choose a reason for hiding this comment

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

could you remove this extraneous line? :D

Suggested change
the augmentation
in a command line
the augmentation

@facebook-github-bot
Copy link
Contributor

@Adib234 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@zpapakipos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Adib234 added a commit to Adib234/AugLy that referenced this pull request Dec 8, 2021
Summary:
- [X ] I have read CONTRIBUTING.md to understand how to contribute to this repository :)

<Please summarize what you are trying to achieve, what changes you made, and how they acheive the desired result.>
I am trying to speed up horizontally flipping, and what I did is use VidGear to execute an ffmpeg command with the preset of ultrafast.

With my changes in running HFlip tests: 4.724 seconds (tests would complete around 2.5 seconds)
Without my changes in running HFlip tests: 12.534 seconds (tests would complete around 10.5 seconds)

I've run each test with and without my changes five times on fish shell with this command `time for i in (seq 5); python -m unittest augly.tests.video_tests.transforms.ffmpeg_test.TransformsVideoUnitTest.test_HFlip;; end`

## Unit Tests
If your changes touch the `audio` module, please run all of the `audio` tests and paste the output here. Likewise for `image`, `text`, & `video`. If your changes could affect behavior in multiple modules, please run the tests for all potentially affected modules. If you are unsure of which modules might be affected by your changes, please just run all the unit tests.

### Audio
```bash
python -m unittest discover -s augly/tests/audio_tests/ -p "*"
```

### Image
```bash
python -m unittest discover -s augly/tests/image_tests/ -p "*_test.py"
# Or `python -m unittest discover -s augly/tests/image_tests/ -p "*.py"` to run pytorch test too (must install `torchvision` to run)
```

### Text
```bash
python -m unittest discover -s augly/tests/text_tests/ -p "*"
```

### Video
```bash
python -m unittest discover -s augly/tests/video_tests/ -p "*"
```

### All
```bash
python -m unittest discover -s augly/tests/ -p "*"
```

## Other testing

If applicable, test your changes and paste the output here. For example, if your changes affect the requirements/installation, then test installing augly in a fresh conda env, then make sure you are able to import augly & run the unit test

Pull Request resolved: facebookresearch#148

Reviewed By: jbitton

Differential Revision: D32591542

Pulled By: zpapakipos

fbshipit-source-id: 83116e0ffe83c1682c6255ac2f65b58716f088f7
Adib234 added a commit to Adib234/AugLy that referenced this pull request Dec 8, 2021
…oise-vflip

* upstream/main:
  Optimize hflip (facebookresearch#148)
  increasing highpass efficiency (facebookresearch#149)
Adib234 added a commit to Adib234/AugLy that referenced this pull request Dec 8, 2021
…34/AugLy into optimize-loop-add_noise-vflip

* 'optimize-merge-video-audio' of https://github.com/Adib234/AugLy: (31 commits)
  Optimize hflip (facebookresearch#148)
  increasing highpass efficiency (facebookresearch#149)
  added newline to match upstream main
  manually changed base_unit_test.py to be in sync with upstream/main
  Remove ci_testing workflow that I was testing
  Remove making new conda env
  Add conda init
  Fix spaces
  Use conda
  Fix python step
  Merge python & reqs steps
  Add CI testing Github action
  added vidgear with version number
  format with black
  replaced video_path with output_path
  removed using the same file path for a ffmpeg command
  using tempfile instead of actually creating a file
  added vidgear as a dependency
  used newer format
  removed uncommented code
  ...
Adib234 added a commit to Adib234/AugLy that referenced this pull request Dec 9, 2021
…34/AugLy into optimize-merge-video-audio

* 'optimize-merge-video-audio' of https://github.com/Adib234/AugLy: (31 commits)
  Optimize hflip (facebookresearch#148)
  increasing highpass efficiency (facebookresearch#149)
  added newline to match upstream main
  manually changed base_unit_test.py to be in sync with upstream/main
  Remove ci_testing workflow that I was testing
  Remove making new conda env
  Add conda init
  Fix spaces
  Use conda
  Fix python step
  Merge python & reqs steps
  Add CI testing Github action
  added vidgear with version number
  format with black
  replaced video_path with output_path
  removed using the same file path for a ffmpeg command
  using tempfile instead of actually creating a file
  added vidgear as a dependency
  used newer format
  removed uncommented code
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants