Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
af2b197
Merge branch 'main' into im-dev
Iainmon May 2, 2025
fa60713
Loading module files in style tranfer works
Iainmon May 2, 2025
9ae5efe
C++ style transfer experiment working.
Iainmon May 2, 2025
e24a7a2
Style transfer c++ experiment sort of works with MPS.
Iainmon May 2, 2025
664ee7d
making process on style transfer demo c++.
Iainmon May 2, 2025
79e37d0
Remove redundanc c++ method, look at changed code.
Iainmon May 2, 2025
8a578b6
Vial works with experement.
Iainmon May 2, 2025
96c9eaa
Working experiment for some reason.
Iainmon May 2, 2025
6a48d50
Fix sobel image example with style_transfer. Working on MPS functiona…
Iainmon May 5, 2025
854e609
Working with color channel swapping in style transfer live demo.
Iainmon May 5, 2025
38fd2e8
Make example style transfer working with identity image function.
Iainmon May 5, 2025
746fd49
Make example style transfer working with identity image function.
Iainmon May 5, 2025
e3f50e8
Make example style transfer working with identity image function.
Iainmon May 5, 2025
309589a
Make example style transfer working with identity image function.
Iainmon May 5, 2025
29b4c11
Swapping color channels working.
Iainmon May 5, 2025
36dcd2c
Style transfer MPS working for some weird reason. Come back to here.
Iainmon May 5, 2025
1084247
sobel.py working in demos/video/style-transfer
Iainmon May 6, 2025
c28025b
StyleTransfer video demo working with sobel_edge_float model
Iainmon May 6, 2025
d44170c
StyleTransfer working with new sobel model
Iainmon May 6, 2025
5efe5d5
Mosaic output working in sobel.py
Iainmon May 7, 2025
a0d42d5
Live mosaic style transfer working in sobel.py
Iainmon May 7, 2025
51b79ff
CPP style transfer demo working with artifacts.
Iainmon May 7, 2025
c46e9cb
Style transfer C++ demo working completely with mosaic. Need to optim…
Iainmon May 7, 2025
40568d4
StyleTransfer mosaic demo working, but not very fast.
Iainmon May 7, 2025
403bcf4
Add files for HPC test.
Iainmon May 7, 2025
ad1c2d4
Fix small code error.
Iainmon May 7, 2025
cc81b63
Add more tests for HPC system.
Iainmon May 7, 2025
2674c09
style transfer demo working.
Iainmon May 7, 2025
9cde73c
Experimenting with Chapel and C event loop interop.
Iainmon May 7, 2025
0096614
Futile compilation attempt working. see new file.
Iainmon May 7, 2025
aa697ac
Added code for training style transfer models on HPC server.
Iainmon May 9, 2025
5aedfa6
Update server train script.
Iainmon May 9, 2025
77dcf53
Made video demo repeat on video loop.
Iainmon May 9, 2025
7df5bf9
Add more model export files from HPC cluster.
Iainmon May 9, 2025
61cdba4
Add model files and server scipts (out of sync).
Iainmon May 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bridge/include/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ proto_bridge_simple(softsign);

proto_bridge_simple(tanhshrink);

void split_loop(int64_t idx, int64_t n);
void split_loop_filler(int64_t n,int64_t* ret);

void show_webcam(void);


// bridge_tensor_t conv2d(
// bridge_tensor_t input,
Expand Down
Binary file added bridge/include/bridge.h.pch
Binary file not shown.
57 changes: 57 additions & 0 deletions bridge/lib/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include <cstdlib>
#include <vector>
#include <cstdint>
#include <chrono>
#include <thread>

#include <opencv2/opencv.hpp>


#define def_bridge_simple(Name) \
extern "C" bridge_tensor_t Name(bridge_tensor_t input) { \
Expand Down Expand Up @@ -381,3 +386,55 @@ extern "C" float sumArray(float* arr, int* sizes, int dim) {
// auto t = torch::from_blob(arr, shape, torch::kFloat);
// return t.sum().item<float>();
}


extern "C" void split_loop(int64_t idx, int64_t n) {
for (int i = 0; i < n; ++i) {
std::cout << "idx(" << idx << "," << n << ") = " << i << std::endl;
std::cout.flush();
}
}

extern "C" void split_loop_filler(int64_t n,int64_t* ret) {
for (int i = 0; i < n; ++i) {
*ret = i;
std::this_thread::sleep_for(std::chrono::seconds(0));
}
}



cv::VideoCapture open_camera(int cam_index) {
cv::VideoCapture cap(cam_index, cv::CAP_AVFOUNDATION);
if (!cap.isOpened()) {
std::cerr << "Could not open camera index " << cam_index << std::endl;
return cv::VideoCapture();
}
cap.set(cv::CAP_PROP_BUFFERSIZE, 1); // minimal internal buffering
cap.set(cv::CAP_PROP_FPS, 60); // request higher FPS if possible
return cap;
}


extern "C" void show_webcam(void) {
cv::VideoCapture cap;
cap = open_camera(0);

cv::Mat frame_bgr;

while (true) {
if (!cap.read(frame_bgr) || frame_bgr.empty()) {
std::cerr << "[WARN] Empty frame, exiting" << std::endl;
break;
}

cv::imshow("webcam", frame_bgr);

if (cv::waitKey(1) == 27) { // ESC key
break;
}
}

cap.release();
cv::destroyAllWindows();
}
61 changes: 53 additions & 8 deletions demos/video/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ find_library(METAL Metal REQUIRED)
find_library(FOUNDATION Foundation REQUIRED)



add_executable(VidStreamer
${CMAKE_CURRENT_SOURCE_DIR}/webcam_infer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cvtool.hpp
${CMAKE_CURRENT_SOURCE_DIR}/imageops.hpp
${CMAKE_CURRENT_SOURCE_DIR}/webcam-capture/webcam_infer.cpp
)

target_include_directories(VidStreamer
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBTORCH_DIR}/include
${LIBTORCH_DIR}/include/torch/csrc/api/include
)

target_link_directories(VidStreamer
PRIVATE
${LIBTORCH_DIR}/lib
)
target_link_directories(VidStreamer PRIVATE ${LIBTORCH_DIR}/lib)

target_link_libraries(VidStreamer
PRIVATE
Expand All @@ -43,10 +40,58 @@ set_target_properties(VidStreamer PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)


if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(VidStreamer PRIVATE -Ofast -flto -ffast-math)
target_link_options(VidStreamer PRIVATE -flto)
endif()







add_executable(StyleTransfer
${CMAKE_CURRENT_SOURCE_DIR}/style-transfer/style_transfer.cpp
)

target_include_directories(StyleTransfer
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBTORCH_DIR}/include
${LIBTORCH_DIR}/include/torch/csrc/api/include
)

target_link_directories(StyleTransfer PRIVATE ${LIBTORCH_DIR}/lib)

target_link_libraries(StyleTransfer
PRIVATE
-ltorch
-ltorch_cpu
-lc10
-ltorch_global_deps
${OpenCV_LIBS}
# ${TORCH_LIBRARIES}
${ACCELERATE}
${METAL}
${FOUNDATION}
)

set_target_properties(StyleTransfer PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(StyleTransfer PRIVATE -Ofast -flto -ffast-math)
target_link_options(StyleTransfer PRIVATE -flto)
endif()


add_custom_command(
TARGET StyleTransfer
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/style-transfer/models"
"$<TARGET_FILE_DIR:StyleTransfer>/style-transfer/models"
COMMENT "NOT! Copying ${PROJECT_ROOT_DIR}/examples/vgg/images to $<TARGET_FILE_DIR:vgg>/images"
)
Loading
Loading