Skip to content

Instantly share code, notes, and snippets.

View ollewelin's full-sized avatar

Olle Welin ollewelin

View GitHub Profile
@ollewelin
ollewelin / CMakeFiles.txt
Created March 3, 2017 19:24
CMakeFiles.txt for NN18.cpp program
#####################################
cmake_minimum_required (VERSION 2.8)
project (raspicam_test)
set(CMAKE_MODULE_PATH "/usr/local/lib/cmake/${CMAKE_MODULE_PATH}")
find_package(raspicam REQUIRED)
find_package(OpenCV)
IF ( OpenCV_FOUND AND raspicam_CV_FOUND)
MESSAGE(STATUS "COMPILING OPENCV TESTS")
#SET_SOURCE_FILES_PROPERTIES( gpio_test.c PROPERTIES LANGUAGE CXX )
@ollewelin
ollewelin / gist:a8a94a7c485c557ba5c84c19682728fc
Last active May 10, 2017 18:39
NN18.cpp update feature learning much better and faster
//Fix bugg 2017-05-10 (....C2M_W....) before (C2M_H,C2M_H...
//Mat pol_c_m1_unpad(C2M_H,C2M_W,CV_32F);//After second pooling befor padding
//2017-05-05 FIX so kernel update weight direct after each pixel step (before there was a sum up all steps togheter dont work prorper). So now the kerenle patches traingin much much faster and better
//the kernels feature now adapt and look's much more like it correspond to the traingin images.
//File: NN18.cpp
//2017-01-17 fix bugg in make_SumChangeFeature0Weights replace c_m1 with m1_conv0
//Ask of loading any reruned training turn
//Rerun fully connected weights (10 times) and lock kernel layer 0 after (2) rerun lock kernel layer 1 after (4) reruns
//Show all kernels in 3 windows
//In this example 6 output nodes and explaned training images set in start of program.
//2017-05-11 fix bugg index was wrong before m32_conv0 = convolute_mat2(&Feature0Kernel[31][0], FE0KSIZESQR, FE0KSIZESQR, m1_0_padded, int (m1_0_padded.cols));// Make a convolution of the image
//2017-05-07 find bugg Mat pol_c_m1_unpad(C2M_H,C2M_W,CV_32F); was before bug fix ..C2M_H,C2M_H..
//2017-05-05 32x32x32 feature stright connection
//2017-05-05 FIX so kernel update weight direct after each pixel step (before there was a sum up all steps togheter dont work prorper). So now the kerenle patches traingin much much faster and better
//the kernels feature now adapt and look's much more like it correspond to the traingin images.
//Add dropout on fully connected HiddenNodes prevent overtraning
//2017-01-17 fix bugg in make_SumChangeFeature0Weights replace c_m1 with m1_conv0
//Ask of loading any reruned training turn
//Rerun fully connected weights (10 times) and lock kernel layer 0 after (2) rerun lock kernel layer 1 after (4) reruns
//Show all kernels in 3 windows
//2017-05-11 fix bugg index was wrong before m32_conv0 = convolute_mat2(&Feature0Kernel[31][0], FE0KSIZESQR, FE0KSIZESQR, m1_0_padded, int (m1_0_padded.cols));// Make a convolution of the image
//2017-05-05 32x32x32 feature stright connection
//2017-05-05 FIX so kernel update weight direct after each pixel step (before there was a sum up all steps togheter dont work prorper). So now the kerenle patches traingin much much faster and better
//the kernels feature now adapt and look's much more like it correspond to the traingin images.
//Add dropout on fully connected HiddenNodes prevent overtraning
//2017-01-17 fix bugg in make_SumChangeFeature0Weights replace c_m1 with m1_conv0
//Ask of loading any reruned training turn
//Rerun fully connected weights (10 times) and lock kernel layer 0 after (2) rerun lock kernel layer 1 after (4) reruns
//Show all kernels in 3 windows
//In this example 6 output nodes and explaned training images set in start of program.
@ollewelin
ollewelin / gist:a29ce1a65a25df89a9f7de3e16a000d5
Created May 6, 2017 07:42
Image transforming tool to produce more training and verify images
//This code take some posXXX.jpg and verXXX.jpg files in program root dir and tranform images to a folder with name \positive_data\posXXX.jpg verXXX.jpg
//#include <stdio.h>
//#include <unistd.h>
//#include <ctime>
//#include <iostream>
//#include <raspicam/raspicam_cv.h>
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
@ollewelin
ollewelin / gist:dd94fc45a99b3fb34a1479270716dc23
Last active May 24, 2017 12:58
Autoencoder neural network raspberry pi
//Autoencoder learning test with raspicam
//press <Y> at start It's tested with 0..9 28x28 pixel digits pattern mnist.png filname 289x289 orginal
//orginal image taken from
// https://blog.webkid.io/datasets-for-machine-learning/
//#define USE_RASPICAM_INPUT //If you want to use raspicam input data
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
@ollewelin
ollewelin / gist:5d88ab7406690ec7414be568004e83b0
Last active May 24, 2017 15:58
Autoencoder test on MNIST data
//Test2 improved and also show (visualize) the noise input stimulu
//Autoencoder learning test with raspicam
//press <Y> at start It's tested with 0..9 28x28 pixel digits pattern mnist.png filname 289x289 orginal
//orginal image taken from
// https://blog.webkid.io/datasets-for-machine-learning/
//#define USE_RASPICAM_INPUT //If you want to use raspicam input data
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
@ollewelin
ollewelin / gist:92eaae7905d7d123fadc97d5c7061e90
Last active May 25, 2017 21:30
Autoencoder test with MNIST 10k dataset traning digits
//Add visualize hidden nodes
//Add so you can save weight by press <S>
//Autoencoder learning test with raspicam
//press <Y> at start It's tested with dataset from
/// t10k-images-idx3-ubyte
/// http://yann.lecun.com/exdb/mnist/
//If you comment out USE_MNIST_DATABASE switch then simpler pattern used from a picture https://blog.webkid.io/datasets-for-machine-learning/
//0..9 28x28 pixel digits pattern mnist.png filname 289x289 orginal
//orginal image taken from
@ollewelin
ollewelin / gist:fe43311536a70fe7a52f0ac16f87ab7f
Last active May 27, 2017 11:52
Raspberry pi Unsupervised learning Autoencoder with bias node
///Now also Add bias nodes showed in the last 2 patches
const float Bias_level = 1.0f;
const float Bias_w_n_range = -1.0f;
const float Bias_w_p_range = 1.0f;
const float change_bias_weight_range = 0.2f;
//Add visualize hidden nodes
//Add so you can save weight by press <S>
//Autoencoder learning test with raspicam
@ollewelin
ollewelin / gist:b5b4c414523ff7b9698aa5b824ae12ba
Last active June 11, 2017 12:39
Autoencoder train 10x10 patches from realtime video raspicam on Raspberry pi
///Now USE_IND_NOISE switch ON make more realistoc gabor filter like feature
/// Fix Bugg replace hidden_node[j] and output_node[i] with Bias_level
// change_weight_in2hid[j] = (LearningRate/2) * hidden_node[j] * hid_node_delta[j] + Momentum * change_weight_in2hid[j];
// change_weight_hid2out[i] = (LearningRate/2) * output_node[i] * delta_pixel + Momentum * change_weight_hid2out[i];
///#define USE_LIM_BIAS//
//Here use real image from raspicam take random part 10x10 pixel and put in to the autoencoder
const int cam_h = 240;