Commit Graph

121 Commits

Author SHA1 Message Date
pfeatherstone decdef12f5
[FFmpeg] decoding and demuxing improvements (#2784)
* typo

* - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio.
- created resizing_args and resampling_args

* smaller videos for unit tests

* shorter videos for unit tests

* - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read()
- added templated read() function
- simplified load_frame()

* inherit from resizing_args and resampling_args

* reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible

* much more basic example

* demxing examples split

* examples

* fixing examples

* wip

* Fix load_frame()

* added frame - specific tests

* - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird.

* notes on defaults and good pairings

* Update ffmpeg_demuxer.h

Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled.

* Update ffmpeg_details.h

* Update ffmpeg_muxer.h

* WIP

* WIP

* - simplified details::resizer
- added frame::set_params()
- added frame::clear()
- forward packet directly into correct queue

* pick best codec if not specified

* added image data

* warn when we're choosing an appropriate codec

* test load_frame()

* - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this.
- you can move freshly decoded frames directly out.

* callback passed to push()

* I think it's prettier this way

* WIP

* full callback API for decoder

* updated tests

* updated example

* check the template parameter is callable and has 1 argument first before getting it's first argument

* Potential bug fix

* - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares
- guard push() with a boolean which asserts when recursion is detected

* pre-conditions on callbacks: no recursion

---------

Co-authored-by: pf <pf@me>
Co-authored-by: Your name <you@example.com>
2023-05-15 21:24:47 -04:00
pfeatherstone 89fc01beb5
FFmpeg : examples (#2764)
* added a couple more audio examples

* Test for ODR violations and include config.h

* Test for ODR violations

---------

Co-authored-by: pf <pf@me>
2023-04-12 22:47:58 -04:00
pfeatherstone 9148a47c7e
RTSP example (#2763) 2023-04-09 10:34:31 -04:00
pfeatherstone 7155daeeea
FFmpeg : muxing (#2755)
* muxing

* Add HSV support (#2758)

* Add HSV support

* Add tests

* Update dlib/pixel.h

Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>

* Add HSV struct and make more things const

---------

Co-authored-by: Davis E. King <davis685@gmail.com>

* Fix imglab changing the current dir too soon (#2761)

* A bit of cleanup

---------

Co-authored-by: pf <pf@me>
Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
Co-authored-by: Davis E. King <davis685@gmail.com>
Co-authored-by: Davis King <davis@dlib.net>
2023-04-08 14:45:30 -04:00
pfeatherstone 937e07e90d
FFmpeg : encoding (#2754)
* docs

* callbacks for encoder

* shorter video

* shorter video

* added is_byte type trait

* leave muxer for next PR

* added overloads for set_layout() and get_layout() in details namespace

* unit test

* example

* build

* overloads for ffmpeg < 5

* Update examples/ffmpeg_video_encoding_ex.cpp

Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>

* Update dlib/media/ffmpeg_abstract.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_abstract.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_abstract.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_abstract.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_abstract.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* as per suggestion

* remove requires clause

* Update examples/ffmpeg_video_encoding_ex.cpp

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_abstract.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_abstract.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_abstract.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_muxer.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* use dlib::logger

* oops

* Update dlib/media/ffmpeg_muxer.h

Co-authored-by: Davis E. King <davis685@gmail.com>

* Update dlib/media/ffmpeg_demuxer.h

* Update dlib/media/ffmpeg_demuxer.h

* Update dlib/media/ffmpeg_abstract.h

---------

Co-authored-by: pf <pf@me>
Co-authored-by: Davis E. King <davis685@gmail.com>
Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
2023-04-01 09:48:26 -04:00
Davis King 049c59d0f6 set correct cmake version in check 2023-03-25 15:56:54 -04:00
Davis King 806b629035 Make everything work in cmake 3.8 2023-03-23 20:07:48 -04:00
Adrià Arrufat 1958da78da
Rename ffmpeg examples (#2727) 2023-02-10 22:03:25 -05:00
pfeatherstone 50b33753bb
Strip binaries in release mode (#2721)
* - use add_executable directly
- use target_compile_definitions()
- strip binaries in release mode

* Added a comment

---------

Co-authored-by: pf <pf@me>
Co-authored-by: Davis E. King <davis685@gmail.com>
2023-02-03 17:43:00 -05:00
pfeatherstone 9d3ba472dd
FFMPEG wrappers: dlib::ffmpeg::decoder and dlib::ffmpeg::demuxer (#2707)
* - added ffmpeg stuff to cmake

* - added observer_ptr

* ffmpeg utils

* WIP

* - added ffmpeg_decoder

* config file for test data

* another test file

* install ffmpeg

* added ffmpeg_demuxer

* install all ffmpeg libraries

* support older version of ffmpeg

* simplified loop

* - test converting to dlib object
- added docs
- support older ffmpeg

* added convert() overload

* added comment

* only register stuff when API not deprecated

* - fixed version issues
- fixed decoding

* added tests for ffmpeg_demuxer

* removed unused code

* test GIF

* added docs

* added audio test

* test for audio

* more tests

* review changes

* don't need observer_ptr

* made deps public. I could be wrong but just in case.

* - added some static asserts. Some areas of the code might do memcpy's on arrays of pixels. This requires the structures to be packed. Check this.
- added convert() functions
- changed default decoder options. By default, always decode to RGB and S16 audio
- added convenience constructor to demuxer

* - no longer need opencv

* oops. I let that slip

* - made a few functions public
- more precise requires clauses

* enhanced example

* - avoid FFMPEG_INITIALIZED being optimized away at link time
- added decoding example

* - avoid -Wunused-parameter error

* constexpr and noexcept correctness. This probably makes no difference to performance, BUT, it's what the core guidelines tell you to do. It does however demonstrate how complicated and unecessarily verbose C++ is becoming. Sigh, maybe one day i'll make the switch to something that doesn't make my eyes twitch.

* - simplified metadata structure

* hopefully more educational

* added another example

* ditto

* typo

* screen grab example

* whoops

* avoid -Wunused-parameter errors

* ditto

* - added methods to av_dict
- print the demuxer format options that were not used
- enhanced webcam_face_pose_ex.cpp so you can set webcam options

* if height and width are specified, attempt to set video_size in format_options. Otherwise set the bilinear resizer.

* updated docs

* once again, the ffmpeg APIs do a lot for you. It's a matter of knowing which APIs  to call.

* made header-only

* - some Werror thing

* don't use type_safe_union

* - templated sample type
- reverted deep copy of AVFrame for frame copy constructor

* - added is_pixel_type and is_pixel_check

* unit tests for pixel traits

* enhanced is_image_type type trait and added is_image_check

* added unit tests for is_image_type

* added pix_traits, improved convert() functions

* bug fix

* get rid of -Werror=unused-variable error

* added a type alias

* that's the last of the manual memcpys gone. We'using ffmpeg API everywhere now for copying frames to buffers and back

* missing doc

* set framerate for webcam

* list input devices

* oops. I was trying to make ffmpeg 5 happy but i've given up on ffmpeg v5 compatibility in this PR. Future PR.

* enhanced the information provided by list_input_devices and list_output_devices

* removed vscode settings.json file

* - added a type trait for checking whether a type is complete. This is useful for writing type traits that check other types have type trait specializations. But also other useful things. For example, std::unique_ptr uses something similar to this.

* Davis was keen to simply check pixel_traits is specialised. That's equivalent to checking pixel_traits<> is complete for some type

* code review

* juse use the void_t in dlib/type_traits.h

* one liners

* just need is_image_check

* more tests for is_image_type

* i think this is correct

* removed printf

* better docs

* Keep opencv out of it

* keep old face pose example, then add new one which uses dlib's ffmpeg wrappers

* revert

* revert

* better docs

* better docs

---------

Co-authored-by: pf <pf@me>
2023-01-29 20:17:34 -05:00
Davis King a12824d425 update example to refer to newer dlib version 2022-12-15 22:15:18 -05:00
Davis King 29288e5d89 Make C++14 and CMake 3.8.0 the new minimum required versions 2022-07-31 17:45:18 -04:00
Adrià Arrufat 2e8bac1915
Add dnn self supervised learning example (#2434)
* wip: loss goes down when training without a dnn_trainer

if I use a dnn_trainer, it segfaults (also with bigger batch sizes...)

* remove commented code

* fix gradient computation (hopefully)

* fix loss computation

* fix crash in input_rgb_image_pair::to_tensor

* fix alias tensor offset

* refactor loss and input layers and complete the example

* add more data augmentation

* add documentation

* add documentation

* small fix in the gradient computation and reuse terms

* fix warning in comment

* use tensor_tools instead of matrix to compute the gradients

* complete the example program

* add support for mult-gpu

* Update dlib/dnn/input_abstract.h

* Update dlib/dnn/input_abstract.h

* Update dlib/dnn/loss_abstract.h

* Update examples/dnn_self_supervised_learning_ex.cpp

* Update examples/dnn_self_supervised_learning_ex.cpp

* Update examples/dnn_self_supervised_learning_ex.cpp

* Update examples/dnn_self_supervised_learning_ex.cpp

* [TYPE_SAFE_UNION] upgrade (#2443)

* [TYPE_SAFE_UNION] upgrade

* MSVC doesn't like keyword not

* MSVC doesn't like keyword and

* added tests for emplate(), copy semantics, move semantics, swap, overloaded and apply_to_contents with non void return types

* - didn't need is_void anymore
- added result_of_t
- didn't really need ostream_helper or istream_helper
- split apply_to_contents into apply_to_contents (return void) and visit (return anything so long as visitor is publicly accessible)

* - updated abstract file

* - added get_type_t
- removed deserialize_helper dupplicate
- don't use std::decay_t, that's c++14

* - removed white spaces
- don't need a return-statement when calling apply_to_contents_impl()
- use unchecked_get() whenever possible to minimise explicit use of pointer casting. lets keep that to a minimum

* - added type_safe_union_size
- added type_safe_union_size_v if C++14 is available
- added tests for above

* - test type_safe_union_size_v

* testing nested unions with visitors.

* re-added comment

* added index() in abstract file

* - refactored reset() to clear()
- added comment about clear() in abstract file
- in deserialize(), only reset the object if necessary

* - removed unecessary comment about exceptions
- removed unecessary // -------------
- struct is_valid is not mentioned in abstract. Instead rather requiring T to be a valid type, it is ensured!
- get_type and get_type_t are private. Client code shouldn't need this.
- shuffled some functions around
- type_safe_union_size and type_safe_union_size_v are removed. not needed
- reset() -> clear()
- bug fix in deserialize() index counts from 1, not 0
- improved the abstract file

* refactored index() to get_current_type_id() as per suggestion

* maybe slightly improved docs

* - HURRAY, don't need std::result_of or std::invoke_result for visit() to work. Just privately define your own type trait, in this case called return_type and return_type_t. it works!
- apply_to_contents() now always calls visit()

* example with private visitor using friendship with non-void return types.

* Fix up contracts

It can't be a post condition that T is a valid type, since the choice of T is up to the caller, it's not something these functions decide.  Making it a precondition.

* Update dlib/type_safe_union/type_safe_union_kernel_abstract.h

* Update dlib/type_safe_union/type_safe_union_kernel_abstract.h

* Update dlib/type_safe_union/type_safe_union_kernel_abstract.h

* - added more tests for copy constructors/assignments, move constructors/assignments, and converting constructors/assignments
- helper_copy -> helper_forward
- added validate_type<T> in a couple of places

* - helper_move only takes non-const lvalue references. So we are not using std::move with universal references !
- use enable_if<is_valid<T>> in favor of validate_type<T>()

* - use enable_if<is_valid<T>> in favor of validate_type<T>()

* - added is_valid_check<>. This wraps enable_if<is_valid<T>,bool> and makes use of SFINAE more robust

Co-authored-by: pfeatherstone <peter@me>
Co-authored-by: pf <pf@me>
Co-authored-by: Davis E. King <davis685@gmail.com>

* Just minor cleanup of docs and renamed some stuff, tweaked formatting.

* fix spelling error

* fix most vexing parse error

Co-authored-by: Davis E. King <davis@dlib.net>
Co-authored-by: pfeatherstone <45853521+pfeatherstone@users.noreply.github.com>
Co-authored-by: pfeatherstone <peter@me>
Co-authored-by: pf <pf@me>
Co-authored-by: Davis E. King <davis685@gmail.com>
2021-10-29 22:26:38 -04:00
Adrià Arrufat 16500906b0
YOLO loss (#2376) 2021-07-29 20:05:54 -04:00
Davis King fbb2db2188 fix example cmake script 2020-04-04 09:55:08 -04:00
Adrià Arrufat f42f100d0f
Add DCGAN example (#2035)
* wip: dcgan-example

* wip: dcgan-example

* update example to use leaky_relu and remove bias from net

* wip

* it works!

* add more comments

* add visualization code

* add example documentation

* rename example

* fix comment

* better comment format

* fix the noise generator seed

* add message to hit enter for image generation

* fix srand, too

* add std::vector overload to update_parameters

* improve training stability

* better naming of variables

make sure it is clear we update the generator with the discriminator's
gradient using fake samples and true labels

* fix comment: generator -> discriminator

* update leaky_relu docs to match the relu ones

* replace not with !

* add Davis' suggestions to make training more stable

* use tensor instead of resizable_tensor

* do not use dnn_trainer for discriminator
2020-03-29 11:07:38 -04:00
Adrià Arrufat 10d7f119ca
Add dnn_introduction3_ex (#1991)
* Add dnn_introduction3_ex
2020-02-07 07:59:36 -05:00
Juha Reunanen d175c35074 Instance segmentation (#1918)
* Add instance segmentation example - first version of training code

* Add MMOD options; get rid of the cache approach, and instead load all MMOD rects upfront

* Improve console output

* Set filter count

* Minor tweaking

* Inference - first version, at least compiles!

* Ignore overlapped boxes

* Ignore even small instances

* Set overlaps_ignore

* Add TODO remarks

* Revert "Set overlaps_ignore"

This reverts commit 65adeff1f8.

* Set result size

* Set label image size

* Take ignore-color into account

* Fix the cropping rect's aspect ratio; also slightly expand the rect

* Draw the largest findings last

* Improve masking of the current instance

* Add some perturbation to the inputs

* Simplify ground-truth reading; fix random cropping

* Read even class labels

* Tweak default minibatch size

* Learn only one class

* Really train only instances of the selected class

* Remove outdated TODO remark

* Automatically skip images with no detections

* Print to console what was found

* Fix class index problem

* Fix indentation

* Allow to choose multiple classes

* Draw rect in the color of the corresponding class

* Write detector window classes to ostream; also group detection windows by class (when ostreaming)

* Train a separate instance segmentation network for each classlabel

* Use separate synchronization file for each seg net of each class

* Allow more overlap

* Fix sorting criterion

* Fix interpolating the predicted mask

* Improve bilinear interpolation: if output type is an integer, round instead of truncating

* Add helpful comments

* Ignore large aspect ratios; refactor the code; tweak some network parameters

* Simplify the segmentation network structure; make the object detection network more complex in turn

* Problem: CUDA errors not reported properly to console
Solution: stop and join data loader threads even in case of exceptions

* Minor parameters tweaking

* Loss may have increased, even if prob_loss_increasing_thresh > prob_loss_increasing_thresh_max_value

* Add previous_loss_values_dump_amount to previous_loss_values.size() when deciding if loss has been increasing

* Improve behaviour when loss actually increased after disk sync

* Revert some of the earlier change

* Disregard dumped loss values only when deciding if learning rate should be shrunk, but *not* when deciding if loss has been going up since last disk sync

* Revert "Revert some of the earlier change"

This reverts commit 6c852124ef.

* Keep enough previous loss values, until the disk sync

* Fix maintaining the dumped (now "effectively disregarded") loss values count

* Detect cats instead of aeroplanes

* Add helpful logging

* Clarify the intention and the code

* Review fixes

* Add operator== for the other pixel types as well; remove the inline

* If available, use constexpr if

* Revert "If available, use constexpr if"

This reverts commit 503d4dd335.

* Simplify code as per review comments

* Keep estimating steps_without_progress, even if steps_since_last_learning_rate_shrink < iter_without_progress_thresh

* Clarify console output

* Revert "Keep estimating steps_without_progress, even if steps_since_last_learning_rate_shrink < iter_without_progress_thresh"

This reverts commit 9191ebc776.

* To keep the changes to a bare minimum, revert the steps_since_last_learning_rate_shrink change after all (at least for now)

* Even empty out some of the previous test loss values

* Minor review fixes

* Can't use C++14 features here

* Do not use the struct name as a variable name
2019-11-14 22:53:16 -05:00
Davis King 1b83016abd update docs 2019-10-24 20:15:34 -04:00
Davis King 39327e71b7 Added note about using cmake's new fetch content feature. 2019-10-24 07:50:30 -04:00
Davis King c9faacce29 Fixed typos 2017-12-25 08:50:34 -05:00
Davis King 22f26ebe97 Improved visual studio compilation instructions 2017-12-16 23:17:37 -05:00
Davis King 46a1893534 Fixed spelling error in comment 2017-12-11 06:40:00 -05:00
Davis King 15c04ab224 This example still uses a lot of visual studio ram. 2017-12-01 00:26:31 -05:00
Davis King 2b3d8609e5 These examples compile now in visual studio due to the recent pragma directive added to core.h. 2017-11-30 22:38:29 -05:00
Juha Reunanen e48125c2a2 Add semantic segmentation example (#943)
* Add example of semantic segmentation using the PASCAL VOC2012 dataset

* Add note about Debug Information Format when using MSVC

* Make the upsampling layers residual as well

* Fix declaration order

* Use a wider net

* trainer.set_iterations_without_progress_threshold(5000); // (was 20000)

* Add residual_up

* Process entire directories of images (just easier to use)

* Simplify network structure so that builds finish even on Visual Studio (faster, or at all)

* Remove the training example from CMakeLists, because it's too much for the 32-bit MSVC++ compiler to handle

* Remove the probably-now-unnecessary set_dnn_prefer_smallest_algorithms call

* Review fix: remove the batch normalization layer from right before the loss

* Review fix: point out that only the Visual C++ compiler has problems.
Also expand the instructions how to run MSBuild.exe to circumvent the problems.

* Review fix: use dlib::match_endings

* Review fix: use dlib::join_rows. Also add some comments, and instructions where to download the pre-trained net from.

* Review fix: make formatting comply with dlib style conventions.

* Review fix: output training parameters.

* Review fix: remove #ifndef __INTELLISENSE__

* Review fix: use std::string instead of char*

* Review fix: update interpolation_abstract.h to say that extract_image_chips can now take the interpolation method as a parameter

* Fix whitespace formatting

* Add more comments

* Fix finding image files for inference

* Resize inference test output to the size of the input; add clarifying remarks

* Resize net output even in calculate_accuracy

* After all crop the net output instead of resizing it by interpolation

* For clarity, add an empty line in the console output
2017-11-15 07:01:52 -05:00
Davis King 978da26ed0 Fixed grammar in comment 2017-11-05 07:37:29 -05:00
Davis King 525bf0e15b Fixed weird wording. 2017-10-17 19:20:29 -04:00
Davis King 3aa9991892 Made comment more clear. 2017-10-17 19:18:57 -04:00
Davis King 3b2d73db68 Some cmake script cleanup and refactoring. 2017-10-16 20:55:28 -04:00
Davis King d39b843de0 Added another car finding example 2017-09-16 15:35:58 -04:00
Davis King 51eae2ba07 Added two vehicle detection examples. 2017-08-26 17:13:47 -04:00
cclough 5fa4533b9a Update CMakeLists.txt (#566) 2017-04-30 20:48:51 -04:00
Davis King df5a087b03 Made it more obvious that this file is a cmake tutorial. Also added a few more comments about how to use cmake. 2017-03-24 09:15:43 -04:00
Davis King 67db08f5a6 Made example cmake use dlib::dlib link name. Also made the installed
cmake config for dlib enable C++11.
2017-02-28 04:43:32 -05:00
Alain Vaucher b41455fd26 Change minimum CMake version that supports the introduced features 2017-02-27 18:23:28 +01:00
Davis King e4402cf575 Don't build face recognition example if GUI support isn't enabled. 2017-02-18 15:33:09 -05:00
Davis King 11016884ed Avoid crashing visual studio 2017-02-12 13:28:42 -05:00
Davis King fe1a15f32a Added face recognition example 2017-02-11 14:52:47 -05:00
Davis King bf36a846de Changed build order to see if it prevents travis from crashing. 2016-12-18 23:35:25 -05:00
Davis King 4d121e7e08 Added another metric learning example 2016-12-17 14:29:29 -05:00
Davis King cb198afc3f Added metric learning example 2016-12-17 10:56:27 -05:00
Davis King 2787edc9bd Improved error messages about non-C++11 compilers and made the example cmake
file a little clearer on this issue.
2016-10-09 18:13:21 -04:00
Davis King f5da9fe2b0 Changed cmake so it compiles most of the DNN examples when using visual studio. 2016-10-08 15:28:58 -04:00
Davis King b5c43a6efd Merge branch 'skip_gui_examples' of git://github.com/miscellanea/dlib into miscellanea-skip_gui_examples
Conflicts:
	examples/CMakeLists.txt
2016-10-02 17:52:39 -04:00
Davis King 16cedfd92e Added more mmod examples. 2016-10-02 13:00:07 -04:00
Xi Deng ea20f5e2ca skip examples which need GUI when DLIB_NO_GUI_SUPPORT is defined 2016-10-01 18:49:57 -07:00
Davis King d5dc371ff8 Added random_cropper and DNN MMOD example programs. 2016-09-05 15:39:31 -04:00
Davis King a76b642a4e renamed examples
--HG--
rename : examples/dnn_mnist_advanced_ex.cpp => examples/dnn_introduction2_ex.cpp
rename : examples/dnn_mnist_ex.cpp => examples/dnn_introduction_ex.cpp
2016-06-25 09:34:53 -04:00
Davis King 541ce716b9 Added the program that made the resnet model. 2016-06-25 09:26:51 -04:00