-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from imaami/a_few_things
Bug fixes and enhancements
- Loading branch information
Showing
14 changed files
with
4,555 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
*.c filter=lfs diff=lfs merge=lfs -text | ||
/Lib/weights.c filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*.args.0 | ||
*.bc | ||
*.d | ||
*.dll | ||
*.i | ||
*.ii | ||
*.lto_wrapper_args | ||
*.ltrans.out | ||
*.ltrans_args | ||
*.o | ||
*.res | ||
*.s | ||
*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "model.h" | ||
|
||
__attribute__((always_inline)) | ||
static inline struct tensors * | ||
tensors_create_helper (char const *const caller) | ||
{ | ||
int e = 0; | ||
struct tensors *t = tensors_create(&e); | ||
|
||
if (!t) { | ||
if (e) | ||
fprintf(stderr, "%s: tensors_create(): %s\n", caller, strerror(e)); | ||
else | ||
fprintf(stderr, "%s: tensors_create() failed\n", caller); | ||
} | ||
|
||
return t; | ||
} | ||
|
||
LIB_EXPORT void | ||
EmotionLib_imageSentiment (EmotionLibImage const *image, | ||
EmotionLibPrediction *result) | ||
{ | ||
struct tensors *ts = tensors_create_helper(__func__); | ||
|
||
if (ts) { | ||
model_infer(ts, image, result); | ||
tensors_destroy(&ts); | ||
} | ||
} | ||
|
||
LIB_EXPORT void | ||
EmotionLib_videoSentiment (EmotionLibImage const *frames, | ||
int num_frames, | ||
EmotionLibPrediction *results, | ||
int *progress) | ||
{ | ||
struct tensors *ts = tensors_create_helper(__func__); | ||
|
||
if (ts) { | ||
for (int i = 0; i < num_frames; i++) { | ||
model_infer(ts, &frames[i], &results[i]); | ||
|
||
if (progress) | ||
(*progress)++; | ||
} | ||
|
||
tensors_destroy(&ts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef EMOTIONLIB_H_ | ||
#define EMOTIONLIB_H_ | ||
|
||
#if defined(_MSC_VER) || defined(_WIN32) | ||
# define EMOTIONLIB_API_EXPORT __declspec(dllexport) | ||
#else | ||
# define EMOTIONLIB_API_EXPORT __attribute__((visibility("default"))) | ||
#endif | ||
|
||
typedef float EmotionLibImage[3][224][224]; | ||
typedef float EmotionLibPrediction[4]; | ||
|
||
// Image inference | ||
EMOTIONLIB_API_EXPORT void | ||
EmotionLib_imageSentiment (EmotionLibImage const *image, | ||
EmotionLibPrediction *result); | ||
|
||
// Video inference | ||
EMOTIONLIB_API_EXPORT void | ||
EmotionLib_videoSentiment (EmotionLibImage const *frames, | ||
int num_frames, | ||
EmotionLibPrediction *results, | ||
int *progress); | ||
|
||
#undef EMOTIONLIB_API_EXPORT | ||
|
||
#endif // EMOTIONLIB_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,62 @@ | ||
# Compiler options | ||
CC = gcc | ||
CFLAGS = -shared -o emotionLib.dll -Wall -Werror -Ofast | ||
override BIN := EmotionLib.dll | ||
override SRC := EmotionLib.c activation.c model.c tensor.c weights.c | ||
override OBJ := $(SRC:%=%.o) | ||
override DEP := $(SRC:%=%.d) | ||
override CC := $(or $(if $(filter default,$(origin CC)),,$(CC)),gcc) | ||
|
||
# Source files | ||
SOURCES = model.c | ||
override undefine WITH_CLANG_CC | ||
USE_CLANG = $(eval USE_CLANG := $$(shell \ | ||
printf '#ifdef __clang__\n1\n#endif\n' | $$(CC) -E -P -xc -))$(USE_CLANG) | ||
|
||
all: $(SOURCES) | ||
$(CC) $(CFLAGS) $(SOURCES) | ||
override BASE_CFLAGS := $(strip -fPIC $(SANITIZE:%=-fsanitize=%) \ | ||
-O$(if $(DEBUG),$(if $(USE_CLANG),0,g) -g3,fast -DNDEBUG) -Wall -Wextra \ | ||
$(if $(USE_CLANG), \ | ||
-Weverything \ | ||
-Wno-c++-compat \ | ||
-Wno-c++98-compat \ | ||
-Wno-disabled-macro-expansion \ | ||
-Wno-fixed-enum-extension \ | ||
-Wno-gnu-empty-struct \ | ||
-Wno-gnu-statement-expression \ | ||
-Wno-gnu-statement-expression-from-macro-expansion \ | ||
-Wno-gnu-zero-variadic-macro-arguments \ | ||
-Wno-switch-enum \ | ||
-Wno-unknown-warning-option \ | ||
-Wno-unsafe-buffer-usage \ | ||
-Wno-used-but-marked-unused) \ | ||
-Wformat=2 -Wno-declaration-after-statement -Wno-unknown-pragmas) | ||
|
||
ifeq (command line,$(origin CFLAGS)) | ||
override USER_CFLAGS := $(CFLAGS) | ||
override EXTRA_CFLAGS := $(strip \ | ||
$(if $(filter -save-temps,$(USER_CFLAGS)), \ | ||
$(if $(USE_CLANG), \ | ||
-Wno-constant-logical-operand \ | ||
-Wno-gnu-line-marker -pipe), \ | ||
-pipe) \ | ||
$(filter-out -flto -pipe,$(USER_CFLAGS))) | ||
else | ||
override undefine USER_CFLAGS | ||
override EXTRA_CFLAGS := -pipe | ||
endif | ||
|
||
ifeq (,$(filter -fno-lto,$(USER_CFLAGS))) | ||
override BASE_CFLAGS := -flto $(BASE_CFLAGS) | ||
endif | ||
|
||
override CFLAGS := $(BASE_CFLAGS) $(EXTRA_CFLAGS) | ||
override LIBS := -lm | ||
|
||
$(BIN): $(OBJ) | ||
$(CC) -shared $(CFLAGS) -o $@ $^ $(LIBS) | ||
|
||
%.c.o: %.c | ||
$(CC) $(CFLAGS) -o $@ -c -I. -MMD -MQ $@ -MF $<.d $< | ||
|
||
-include $(DEP) | ||
|
||
.PHONY: clean | ||
clean: override WHAT = $(wildcard \ | ||
$(BIN) $(OBJ) $(DEP) *.args.0 *.bc *.i *.ii *.lto_wrapper_args \ | ||
*.ltrans_args *.ltrans0.o *.ltrans.o *.ltrans.out *.res *.s *.temp.o) | ||
clean:; $(if $(WHAT),$(RM) $(WHAT),@:) |
Oops, something went wrong.