Skip to content

Commit 6cbf1c5

Browse files
authored
Develop demos for Capstone Expo (#69)
Thought for a second ## Key Additions ### 1. Python-based Demos - **Sobel edge style transfer** - `sobel.py` image and video demos using `sobel_edge_float` model - Live mosaic output in video pipeline - **Live mosaic style transfer** - Real-time mosaic effect on camera/video stream - **Color channel swapping** - Interactive demo for swapping RGB channels as a “style” - **Identity image function** - Baseline style transfer for verifying pipeline correctness ### 2. C++ Experiments - **Core C++ implementation** - Basic style transfer pipeline with artifacts - **MPS acceleration (macOS)** - Proof-of-concept C++ demo leveraging Apple’s Metal Performance Shaders - **Live mosaic C++ demo** - End-to-end pipeline (performance tuning pending) ### 3. HPC Integration & Training - **Training scripts** - Cluster-ready code for training style models on HPC server - Updated server training and export scripts - **Model export files** - Check-in of pre-trained models from HPC - **Automated HPC tests** - Added test files and CI jobs for high-performance computing validation ### 4. Miscellaneous - **Chapel/Event-loop Interop** - Prototype showing Chapel + C event-loop integration - **Branch Maintenance** - Synced with `main` to resolve conflicts
2 parents b914e33 + 61cdba4 commit 6cbf1c5

185 files changed

Lines changed: 3944 additions & 19 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.

bridge/include/bridge.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ proto_bridge_simple(softsign);
104104

105105
proto_bridge_simple(tanhshrink);
106106

107+
void split_loop(int64_t idx, int64_t n);
108+
void split_loop_filler(int64_t n,int64_t* ret);
109+
110+
void show_webcam(void);
111+
107112

108113
// bridge_tensor_t conv2d(
109114
// bridge_tensor_t input,

bridge/include/bridge.h.pch

1.13 MB
Binary file not shown.

bridge/lib/bridge.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#include <cstdlib>
1414
#include <vector>
1515
#include <cstdint>
16+
#include <chrono>
17+
#include <thread>
18+
19+
#include <opencv2/opencv.hpp>
20+
1621

1722
#define def_bridge_simple(Name) \
1823
extern "C" bridge_tensor_t Name(bridge_tensor_t input) { \
@@ -381,3 +386,55 @@ extern "C" float sumArray(float* arr, int* sizes, int dim) {
381386
// auto t = torch::from_blob(arr, shape, torch::kFloat);
382387
// return t.sum().item<float>();
383388
}
389+
390+
391+
extern "C" void split_loop(int64_t idx, int64_t n) {
392+
for (int i = 0; i < n; ++i) {
393+
std::cout << "idx(" << idx << "," << n << ") = " << i << std::endl;
394+
std::cout.flush();
395+
}
396+
}
397+
398+
extern "C" void split_loop_filler(int64_t n,int64_t* ret) {
399+
for (int i = 0; i < n; ++i) {
400+
*ret = i;
401+
std::this_thread::sleep_for(std::chrono::seconds(0));
402+
}
403+
}
404+
405+
406+
407+
cv::VideoCapture open_camera(int cam_index) {
408+
cv::VideoCapture cap(cam_index, cv::CAP_AVFOUNDATION);
409+
if (!cap.isOpened()) {
410+
std::cerr << "Could not open camera index " << cam_index << std::endl;
411+
return cv::VideoCapture();
412+
}
413+
cap.set(cv::CAP_PROP_BUFFERSIZE, 1); // minimal internal buffering
414+
cap.set(cv::CAP_PROP_FPS, 60); // request higher FPS if possible
415+
return cap;
416+
}
417+
418+
419+
extern "C" void show_webcam(void) {
420+
cv::VideoCapture cap;
421+
cap = open_camera(0);
422+
423+
cv::Mat frame_bgr;
424+
425+
while (true) {
426+
if (!cap.read(frame_bgr) || frame_bgr.empty()) {
427+
std::cerr << "[WARN] Empty frame, exiting" << std::endl;
428+
break;
429+
}
430+
431+
cv::imshow("webcam", frame_bgr);
432+
433+
if (cv::waitKey(1) == 27) { // ESC key
434+
break;
435+
}
436+
}
437+
438+
cap.release();
439+
cv::destroyAllWindows();
440+
}

demos/video/CMakeLists.txt

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ find_library(METAL Metal REQUIRED)
99
find_library(FOUNDATION Foundation REQUIRED)
1010

1111

12+
1213
add_executable(VidStreamer
13-
${CMAKE_CURRENT_SOURCE_DIR}/webcam_infer.cpp
14-
${CMAKE_CURRENT_SOURCE_DIR}/cvtool.hpp
15-
${CMAKE_CURRENT_SOURCE_DIR}/imageops.hpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/webcam-capture/webcam_infer.cpp
1615
)
1716

1817
target_include_directories(VidStreamer
1918
PRIVATE
19+
${CMAKE_CURRENT_SOURCE_DIR}/include
2020
${LIBTORCH_DIR}/include
2121
${LIBTORCH_DIR}/include/torch/csrc/api/include
2222
)
2323

24-
target_link_directories(VidStreamer
25-
PRIVATE
26-
${LIBTORCH_DIR}/lib
27-
)
24+
target_link_directories(VidStreamer PRIVATE ${LIBTORCH_DIR}/lib)
2825

2926
target_link_libraries(VidStreamer
3027
PRIVATE
@@ -43,10 +40,58 @@ set_target_properties(VidStreamer PROPERTIES
4340
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
4441
)
4542

46-
4743
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
4844
target_compile_options(VidStreamer PRIVATE -Ofast -flto -ffast-math)
4945
target_link_options(VidStreamer PRIVATE -flto)
5046
endif()
5147

5248

49+
50+
51+
52+
53+
54+
add_executable(StyleTransfer
55+
${CMAKE_CURRENT_SOURCE_DIR}/style-transfer/style_transfer.cpp
56+
)
57+
58+
target_include_directories(StyleTransfer
59+
PRIVATE
60+
${CMAKE_CURRENT_SOURCE_DIR}/include
61+
${LIBTORCH_DIR}/include
62+
${LIBTORCH_DIR}/include/torch/csrc/api/include
63+
)
64+
65+
target_link_directories(StyleTransfer PRIVATE ${LIBTORCH_DIR}/lib)
66+
67+
target_link_libraries(StyleTransfer
68+
PRIVATE
69+
-ltorch
70+
-ltorch_cpu
71+
-lc10
72+
-ltorch_global_deps
73+
${OpenCV_LIBS}
74+
# ${TORCH_LIBRARIES}
75+
${ACCELERATE}
76+
${METAL}
77+
${FOUNDATION}
78+
)
79+
80+
set_target_properties(StyleTransfer PROPERTIES
81+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
82+
)
83+
84+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
85+
target_compile_options(StyleTransfer PRIVATE -Ofast -flto -ffast-math)
86+
target_link_options(StyleTransfer PRIVATE -flto)
87+
endif()
88+
89+
90+
add_custom_command(
91+
TARGET StyleTransfer
92+
POST_BUILD
93+
COMMAND ${CMAKE_COMMAND} -E copy_directory
94+
"${CMAKE_CURRENT_SOURCE_DIR}/style-transfer/models"
95+
"$<TARGET_FILE_DIR:StyleTransfer>/style-transfer/models"
96+
COMMENT "NOT! Copying ${PROJECT_ROOT_DIR}/examples/vgg/images to $<TARGET_FILE_DIR:vgg>/images"
97+
)

0 commit comments

Comments
 (0)