File tree Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Original file line number Diff line number Diff line change 31
31
run : |
32
32
sudo apt -y install libtbb-dev
33
33
sudo apt install libopencv-dev
34
-
34
+ - name : Install argparse
35
+ run : |
36
+ git clone https://github.com/p-ranav/argparse
37
+ cd argparse
38
+ mkdir build
39
+ cd build
40
+ cmake -DARGPARSE_BUILD_SAMPLES=off -DARGPARSE_BUILD_TESTS=off ..
41
+ sudo make install
35
42
# Alternatively, you can install OpenCV from source
36
43
# - name: Install OpenCV from source
37
44
# run: |
Original file line number Diff line number Diff line change 1
1
#include < torch/torch.h>
2
-
2
+ # include < argparse/argparse.hpp >
3
3
#include < cmath>
4
4
#include < cstdio>
5
5
#include < iostream>
@@ -95,18 +95,21 @@ nn::Sequential create_discriminator() {
95
95
}
96
96
97
97
int main (int argc, const char * argv[]) {
98
-
99
- if (argc > 1 ) {
100
- std::string arg = argv[1 ];
101
- if (std::all_of (arg.begin (), arg.end (), ::isdigit)) {
102
- try {
103
- kNumberOfEpochs = std::stoll (arg);
104
- } catch (const std::invalid_argument& ia) {
105
- // If unable to parse, do nothing and keep the default value
106
- }
107
- }
98
+ argparse::ArgumentParser parser (" cpp/dcgan example" );
99
+ parser.add_argument (" --epochs" )
100
+ .help (" Number of epochs to train" )
101
+ .default_value (kNumberOfEpochs )
102
+ .scan <' i' , int64_t >();
103
+ try {
104
+ parser.parse_args (argc, argv);
105
+ } catch (const std::exception& err) {
106
+ std::cout << err.what () << std::endl;
107
+ std::cout << parser;
108
+ std::exit (1 );
108
109
}
109
- std::cout << " Traning with number of epochs: " << kNumberOfEpochs << std::endl;
110
+ kNumberOfEpochs = parser.get <int64_t >(" --epochs" );
111
+ std::cout << " Traning with number of epochs: " << kNumberOfEpochs
112
+ << std::endl;
110
113
111
114
torch::manual_seed (1 );
112
115
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ function dcgan() {
102
102
make
103
103
if [ $? -eq 0 ]; then
104
104
echo " Successfully built $EXAMPLE "
105
- ./$EXAMPLE 5 # Run the executable with kNumberOfEpochs = 5
105
+ ./$EXAMPLE --epochs 5 # Run the executable with kNumberOfEpochs = 5
106
106
check_run_success $EXAMPLE
107
107
else
108
108
error " Failed to build $EXAMPLE "
You can’t perform that action at this time.
0 commit comments