Skip to content

Commit aa697ac

Browse files
committed
Added code for training style transfer models on HPC server.
1 parent 0096614 commit aa697ac

50 files changed

Lines changed: 881 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
train2014.zip
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/usr/bin/clang++ -std=c++20 -c -fPIC mirror.cpp -o mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
2+
3+
/usr/bin/clang++ -shared -o libmirror.dylib mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps

demos/video/style-transfer/download_saved_models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ def unzip(source_filename, dest_dir):
2626
if __name__ == '__main__':
2727
_download_url_to_file('https://www.dropbox.com/s/lrvwfehqdcxoza8/saved_models.zip?dl=1', 'saved_models.zip', None, True)
2828
unzip('saved_models.zip', '.')
29+
_download_url_to_file('http://images.cocodataset.org/zips/train2014.zip', 'train2014.zip', None, True)
30+
unzip('train2014.zip', '.')
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
4+
MODEL_NAME="oil_h_bt4_5e11_ep4_epoch_0_batch_id_18000"
5+
6+
python3 neural_style.py export --model saved_models/${MODEL_NAME}.pth --accel
7+
8+
python3 style_transfer_test.py --model-file=models/exports/cpu/${MODEL_NAME}_float16.pt --input-video-file=videos/deer.mp4 --show-output
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
python3 neural_style.py export --model saved_models/ckpt_epoch_0_batch_id_18000.pth --accel
2+
# python3 style_transfer_test.py --model-file=models/exports/cpu/ckpt_epoch_0_batch_id_18000_float16.pt --use-webcam --show-output
3+
4+
python3 style_transfer_test.py --model-file=models/exports/cpu/ckpt_epoch_0_batch_id_18000_float16.pt --input-video-file=videos/deer.mp4 --show-output
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
5378 clang++ mirror.cpp
2+
5379 clang++ mirror.cpp -o mirror -I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui
3+
5380 clang++ mirror.cpp -o mirror $(pkg-config --cflags --libs opencv)
4+
5381 clang++ mirror.cpp -o mirror $(pkg-config --cflags --libs opencv4)
5+
5382 ls
6+
5383 ./mirror
7+
5384 clang++ mirror.cpp -o mirror -I $(pkg-config --cflags --libs opencv4)
8+
5385 ls
9+
5386 clang++ mirror.cpp -o mirror $(pkg-config --cflags --libs opencv4)
10+
5387 pwd
11+
5388 clang++ mirror.cpp -o mirror $(pkg-config --cflags --libs opencv4)
12+
5389 ls ../../
13+
5390 ls ../../../
14+
5391 clang++ mirror.cpp -o mirror $(pkg-config --cflags --libs opencv4) -I ../../../libtorch/include -I ../../../include/torch/csrc/api/include
15+
5392 clang++ style_transfer.cpp -o styletransfer $(pkg-config --cflags --libs opencv4) -I ../../../libtorch/include -I ../../../include/torch/csrc/api/include
16+
5393 clang++ style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4)
17+
5394 pwd
18+
5395 ls ../../
19+
5396 ls ../../..
20+
5397 ls ../../../libtorch
21+
5398 ls ../../../libtorch/include
22+
5399 clang++ style_transfer.cpp -o styletransfer -I../../../libtorch/include -I../../../include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4)
23+
5400 clang style_transfer.cpp -o styletransfer -I../../../libtorch/include -I../../../include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4)
24+
5401 clang style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4)
25+
5402 clang style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4)
26+
5403 /usr/bin/clang style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4)
27+
5404 clang style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4)
28+
5405 g++ style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4)
29+
5406 clang -std=c++20 style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4)
30+
5407 clang -std=c++17 style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4)
31+
5408 /usr/bin/clang -std=c++17 style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4)
32+
5409 /usr/bin/clang -std=c++17 style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
33+
5410 /usr/bin/clang -std=c++20 style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
34+
5411 /usr/bin/clang++ -std=c++20 style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
35+
5412 pwd
36+
5413 git add --all
37+
5414 git commit -m "Futile compilation attempt working. see new file. "
38+
5415 git push
39+
5416 /usr/bin/clang++ -std=c++20 style_transfer.cpp -o styletransfer -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include -I ../include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
40+
5417 ls
41+
5418 otool -L styletransfer
42+
5419 /usr/bin/clang++ -std=c++20 mirror.cpp -o mirror -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
43+
5420 /usr/bin/clang++ -std=c++20 -c -fPIC mirror.cpp -o mirror -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
44+
5421 /usr/bin/clang++ -std=c++20 -c -fPIC mirror.cpp -o mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
45+
5422 ls
46+
5423 otool -L mirror.o
47+
5424 /usr/bin/clang++ -std=c++20 -c -fPIC mirror.cpp -o mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
48+
5425 /usr/bin/clang++ -shared -o libmirror.dylib mirror.o
49+
5426 /usr/bin/clang++ -shared -o libmirror.dylib mirror.o -I ../../../libtorch/include -I ../../../libtorch/include/torch/csrc/api/include $(pkg-config --cflags --libs opencv4) -L ../../../libtorch/lib -ltorch -ltorch_cpu -lc10 -ltorch_global_deps
50+
5427 ls
51+
5428 otool
40.6 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
use CTypes;
3+
4+
require "mirror.h", "-lmirror";
5+
6+
extern proc run_mirror(): void;
7+
8+
9+
proc main(args: [] string) {
10+
writeln("Hello, world!");
11+
12+
run_mirror();
13+
}

demos/video/style-transfer/mirror.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include <opencv2/opencv.hpp>
22
#include <iostream>
3+
#include "mirror.h"
34

4-
int main() {
5+
extern "C" void run_mirror() {
56
cv::VideoCapture cap(0); // Open the default camera (0)
67
if (!cap.isOpened()) {
78
std::cerr << "Error: Could not open camera." << std::endl;
8-
return -1;
99
}
1010

1111
cv::Mat frame;
@@ -22,5 +22,5 @@ int main() {
2222

2323
cap.release(); // Release the camera
2424
cv::destroyAllWindows(); // Close all OpenCV windows
25-
return 0;
26-
}
25+
}
26+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
#ifndef MIRROR_H
3+
#define MIRROR_H
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
void run_mirror();
10+
11+
#ifdef __cplusplus
12+
}
13+
#endif
14+
15+
#endif // MIRROR_H

0 commit comments

Comments
 (0)