tmp
This commit is contained in:
parent
65cb26a627
commit
1ead32d84a
71 changed files with 199 additions and 282 deletions
|
|
@ -22,11 +22,8 @@ add_executable(NumRecApp applications/NumRecApp.cpp)
|
|||
target_link_libraries(NumRecApp ${PROJECT_NAME} Connection ImageIO)
|
||||
|
||||
### -------------------------- Tests -------------------------- ###
|
||||
enable_testing()
|
||||
file(GLOB TEST_SOURCES "./tests/*.cpp" "./tests/*/*.cpp")
|
||||
add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES})
|
||||
|
||||
target_include_directories(${PROJECT_NAME}Tests PUBLIC ./applications/)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} UnitTest++)
|
||||
add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests)
|
||||
add_executable(Test${PROJECT_NAME} ${TEST_SOURCES})
|
||||
target_include_directories(Test${PROJECT_NAME} PUBLIC ./applications/)
|
||||
target_link_libraries(Test${PROJECT_NAME} ${PROJECT_NAME} UnitTest++)
|
||||
add_test(NAME Test${PROJECT_NAME} COMMAND Test${PROJECT_NAME})
|
||||
|
|
|
|||
|
|
@ -62,16 +62,7 @@ int main(int argc, char** argv) {
|
|||
imageName = argv[1];
|
||||
}
|
||||
|
||||
ModuleManifest* deps[] = { &gModuleDataAnalysis, &gModuleConnection, nullptr };
|
||||
ModuleManifest module = ModuleManifest("NumRec", nullptr, nullptr, deps);
|
||||
|
||||
if (!module.initialize()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
executeCmd(imageName);
|
||||
|
||||
module.deinitialize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -24,12 +24,12 @@ void writeImage(const Buffer<halnf>& image, const char* name) {
|
|||
|
||||
struct Dataset {
|
||||
ualni length = 0;
|
||||
Pair<ualni, ualni> imageSize = { 0, 0 };
|
||||
std::pair<ualni, ualni> imageSize = { 0, 0 };
|
||||
Buffer<uint1> labels;
|
||||
Buffer<Buffer<uint1>> images;
|
||||
};
|
||||
|
||||
bool loadDataset(Dataset& out, const String& location) {
|
||||
bool loadDataset(Dataset& out, const std::string& location) {
|
||||
LocalConnection dataset;
|
||||
dataset.connect(LocalConnection::Location(location), LocalConnection::Type(true));
|
||||
|
||||
|
|
@ -207,51 +207,38 @@ public:
|
|||
};
|
||||
|
||||
int main() {
|
||||
ModuleManifest* deps[] = { &gModuleDataAnalysis, &gModuleConnection, nullptr };
|
||||
ModuleManifest module = ModuleManifest("NumRec", nullptr, nullptr, deps);
|
||||
NumberRec app;
|
||||
|
||||
if (!module.initialize()) {
|
||||
return 1;
|
||||
}
|
||||
auto numBatches = 10;
|
||||
auto trainRange = Range(0, 50000);
|
||||
auto testRange = Range(50000, 70000);
|
||||
|
||||
{
|
||||
NumberRec app;
|
||||
auto batchSize = trainRange.idxDiff() / numBatches;
|
||||
|
||||
auto numBatches = 10;
|
||||
auto trainRange = Range(0, 50000);
|
||||
auto testRange = Range(50000, 70000);
|
||||
for (auto epoch : Range(1)) {
|
||||
printf("Epoch %i\n", epoch.index());
|
||||
|
||||
auto batchSize = trainRange.idxDiff() / numBatches;
|
||||
for (auto batchIdx : Range(trainRange.idxDiff() / batchSize)) {
|
||||
printf(" - Batch :%i \n", batchIdx.index());
|
||||
|
||||
for (auto epoch : Range(1)) {
|
||||
printf("Epoch %i\n", epoch.index());
|
||||
auto batchRange = Range(trainRange.idxBegin() + batchSize * batchIdx, trainRange.idxBegin() + batchSize * (batchIdx + 1));
|
||||
|
||||
for (auto batchIdx : Range(trainRange.idxDiff() / batchSize)) {
|
||||
printf(" - Batch :%i \n", batchIdx.index());
|
||||
app.trainStep(batchRange);
|
||||
|
||||
auto batchRange = Range(trainRange.idxBegin() + batchSize * batchIdx, trainRange.idxBegin() + batchSize * (batchIdx + 1));
|
||||
|
||||
app.trainStep(batchRange);
|
||||
|
||||
printf("Cost on batch data : %f\n", app.test(batchRange));
|
||||
}
|
||||
|
||||
printf("Cost on test data : %f\n\n", app.test(testRange));
|
||||
printf("Cost on batch data : %f\n", app.test(batchRange));
|
||||
}
|
||||
|
||||
auto errors = 0;
|
||||
for (auto i : testRange) {
|
||||
if (app.testIncorrect(i)) {
|
||||
errors++;
|
||||
}
|
||||
// app.debLog(i);
|
||||
// app.displayImage(i);
|
||||
}
|
||||
|
||||
printf("\n\nIncorrect - %i out of %i (%f)\n\n", errors, testRange.idxDiff(), (halnf) errors / (halnf) testRange.idxDiff());
|
||||
printf("Cost on test data : %f\n\n", app.test(testRange));
|
||||
}
|
||||
|
||||
module.deinitialize();
|
||||
auto errors = 0;
|
||||
for (auto i : testRange) {
|
||||
if (app.testIncorrect(i)) {
|
||||
errors++;
|
||||
}
|
||||
// app.debLog(i);
|
||||
// app.displayImage(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
printf("\n\nIncorrect - %i out of %i (%f)\n\n", errors, testRange.idxDiff(), (halnf) errors / (halnf) testRange.idxDiff());
|
||||
}
|
||||
|
|
@ -4,6 +4,6 @@
|
|||
#include "MathCommon.hpp"
|
||||
|
||||
namespace tp {
|
||||
static ModuleManifest* deps[] = { &gModuleMath, &gModuleContainers, &gModuleAllocators, nullptr };
|
||||
static ModuleManifest* deps[] = { &gModuleAllocators, nullptr };
|
||||
ModuleManifest gModuleDataAnalysis = ModuleManifest("DataAnalysis", nullptr, nullptr, deps);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,22 +24,27 @@ SUITE(FCNN) {
|
|||
}
|
||||
|
||||
FCNN nn(layers);
|
||||
halnf steppingValue = 100;
|
||||
halnf steppingValue = 0.01;
|
||||
|
||||
for (auto i : Range(50)) {
|
||||
halnf cost = 0;
|
||||
|
||||
for (auto i : Range(150)) {
|
||||
|
||||
nn.evaluate(input, output);
|
||||
|
||||
nn.calcGrad(outputExpected);
|
||||
nn.applyGrad(steppingValue);
|
||||
|
||||
cost = nn.calcCost(outputExpected);
|
||||
printf("Loss %f \n", nn.calcCost(outputExpected));
|
||||
}
|
||||
|
||||
CHECK(cost < 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
tp::ModuleManifest* deps[] = { &tp::gModuleDataAnalysis, &tp::gModuleUtils, nullptr };
|
||||
tp::ModuleManifest* deps[] = { &tp::gModuleDataAnalysis, nullptr };
|
||||
tp::ModuleManifest testModule("DataAnalysisTest", nullptr, nullptr, deps);
|
||||
|
||||
if (!testModule.initialize()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue