Skip to content

Commit

Permalink
fix use of utils
Browse files Browse the repository at this point in the history
  • Loading branch information
leovandriel committed Oct 13, 2017
1 parent 3206f09 commit c522427
Show file tree
Hide file tree
Showing 19 changed files with 936 additions and 1,096 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ This tutorial is transcribed in [rnn.cc](src/caffe2/binaries/rnn.cc). It takes t

./bin/rnn

In contrast to the tutorial, this script terminates after 10K iterations. To get more, use `--train_runs`:
In contrast to the tutorial, this script terminates after 10K iterations. To get more, use `--train-runs`:

./bin/run --train_runs 100000
./bin/run --train-runs 100000

To get better results (loss < 1), expand the hidden layer:

./bin/rnn --train_runs 100000 --batch_size 32 --hidden_size 512 --seq_length 32
./bin/rnn --train-runs 100000 --batch-size 32 --hidden-size 512 --seq-length 32

The file `res/dickens.txt` contains a larger volume of text. Because the writing is a bit more recent, it's more challenging to generate convincing results. Also, single newlines are stripped to allow for more creativity.

./bin/rnn --train_runs 100000 --batch_size 32 --hidden_size 768 --seq_length 32 --train_data res/dickens.txt
./bin/rnn --train-runs 100000 --batch-size 32 --hidden-size 768 --seq-length 32 --train-data res/dickens.txt

After 200K runs, the loss has not dropped below 36, in contrast to the shakespeare text. Perhaps this requires an additional hidden layer in the LSTM model.

Expand All @@ -150,7 +150,7 @@ Much of the progress in image recognition is published after the yearly [ImageNe

To classify the content of an image, run:

./bin/imagenet --model <name-of-model> --image_file <some-image>
./bin/imagenet --model <name-of-model> --image-file <some-image>

Where the model name is one of the following:

Expand Down Expand Up @@ -180,21 +180,21 @@ The article [DeCAF: A Deep Convolutional Activation Feature for Generic Visual R

First divide all images in subfolders with the label a folder name. Then to retrain the final layer of GoogleNet:

./bin/retrain --model googlenet --folder <image-folder> --layer pool5/7x7_s1
./bin/train --model googlenet --folder <image-folder> --layer pool5/7x7_s1

The script starts out by collecting all images and running them through the pre-trained part of the model. This allows for very fast training on the pre-processed image data.

If you have more (GPU) power at your disposal retrain VGG16's final 2 layers:

./bin/retrain --model vgg16 --folder <image-folder> --layer fc6
./bin/train --model vgg16 --folder <image-folder> --layer fc6

Some models, like SqueezeNet require reshaping of their output to N x D tensor:

./bin/retrain --model squeezenet --folder <image-folder> --layer fire9/concat --reshape_output
./bin/train --model squeezenet --folder <image-folder> --layer fire9/concat --reshape-output

You can also provide your own pre-trained model. Specify the location of the init and predict `.pb` file including a `%` character:

./bin/retrain --model res/googlenet_%_net.pb --folder <image-folder> --layer pool5/7x7_s1
./bin/train --model res/googlenet_%_net.pb --folder <image-folder> --layer pool5/7x7_s1

See also:

Expand All @@ -203,7 +203,7 @@ See also:

## Training from scratch

To fully train an existing image classification model from scratch, run:
To fully train an existing image classification model from scratch, run without the `--layer` option:

./bin/train --model <model-name> --folder <image-folder>

Expand All @@ -213,7 +213,7 @@ Add `--display` for training visualization.

Some models, like SqueezeNet require reshaping of their output to N x D tensor:

./bin/train --model squeezenet --folder <image-folder> --reshape_output
./bin/train --model squeezenet --folder <image-folder> --reshape-output

## Deep Dream

Expand Down
7 changes: 4 additions & 3 deletions include/caffe2/util/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ bool cmd_setup_cuda() {
option.set_device_type(CUDA);
#ifdef WITH_CUDA
new CUDAContext(option);
std::cout << std::endl << "using CUDA" << std::endl;
return true;
#else
return false;
Expand Down Expand Up @@ -50,11 +49,13 @@ bool cmd_init(const std::string title) {
return false;
}

if (FLAGS_device != "cpu") cmd_setup_cuda();
auto cuda = (FLAGS_device != "cpu" && cmd_setup_cuda());

std::cout << "optimizer: " << FLAGS_optimizer << std::endl;
std::cout << "device: " << FLAGS_device << std::endl;
std::cout << "dump_model: " << (FLAGS_dump_model ? "true" : "false")
std::cout << "using cuda: " << (cuda ? "true" : "false") << std::endl;
;
std::cout << "dump-model: " << (FLAGS_dump_model ? "true" : "false")
<< std::endl;

return true;
Expand Down
Loading

0 comments on commit c522427

Please sign in to comment.