Lua Neural Network

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
bobbyjones
Party member
Posts: 720
Joined: Sat Apr 26, 2014 7:46 pm

Lua Neural Network

Post by bobbyjones » Wed May 15, 2019 6:53 pm

This semester in college I took a computer vision course. In this course, I was required to write a program that can determine if the silhouette of an image is a dog, cat, bird, or dolphin. This program was required to use a Neural Network. Me being very well versed in Lua decided to implement my assignment in Lua/Löve. I extracted the Lua Neural Network and put it in its own GitHub repository. I am really interested in Neural Networks so I plan to expand on this a great deal, but currently, it is extremely simple. I based this code off of a gist I found online. Attached is a horrible example in use. Hopefully, I will make a better example in the future.

https://github.com/Bobbyjoness/LuaNeuralNet/tree/master
Attachments
example.love
(710.19 KiB) Downloaded 91 times
Do you frequently have great ideas but immediately lose them? Check out the MVP for my website called IdeaVault. It is designed to solve that problem. Desktop browsers only currently.

dusoft
Citizen
Posts: 95
Joined: Fri Nov 08, 2013 12:07 am

Re: Lua Neural Network

Post by dusoft » Wed May 15, 2019 9:32 pm

What's the code doing? I see some line only.

bobbyjones
Party member
Posts: 720
Joined: Sat Apr 26, 2014 7:46 pm

Re: Lua Neural Network

Post by bobbyjones » Wed May 15, 2019 9:38 pm

It is training the neural net to classify birds, dogs, cats, and dolphins. The line is the softmax value. Essentially its Accuracy/Epoch.
Edit: I meant its accuracy as y and x is epoch(training cycle) it is a graph.
Do you frequently have great ideas but immediately lose them? Check out the MVP for my website called IdeaVault. It is designed to solve that problem. Desktop browsers only currently.

caralse
Prole
Posts: 1
Joined: Fri May 17, 2019 9:47 am

Re: Lua Neural Network

Post by caralse » Fri May 17, 2019 9:52 am

Hi! I wrote this code using your Network but it doesn't work.
What am I missing?

Code: Select all

local NeuralNetwork = require("lnn")
math.randomseed(os.time())
local nn = NeuralNetwork.create(2, 1, 2, 2, 0.3)
local training_data = {
	{
		inputs = {0, 1},
		target = {1}
	},
	{
		inputs = {1, 1},
		target = {0}
	},
	{
		inputs = {1, 0},
		target = {1}
	},
	{
		inputs = {0, 0},
		target = {0}
	}
}

for i = 1, 2000 do
	local data = training_data[math.random(#training_data)]
	nn:backwardPropagate(data.inputs, data.target)
end
print(nn:forwardPropagate({0, 1})[1])
print(nn:forwardPropagate({1, 1})[1])
print(nn:forwardPropagate({0, 0})[1])
print(nn:forwardPropagate({1, 0})[1])
That just prints 1.

User avatar
yintercept
Citizen
Posts: 61
Joined: Mon Apr 02, 2018 3:31 pm

Re: Lua Neural Network

Post by yintercept » Sat May 18, 2019 6:44 pm

Cool as hell

A guy made something lsimilar back in april, you might enjoy talking with him and sharing notes bobby.


viewtopic.php?f=5&t=85089&p=226763&hilit=neural#p226763
Apparently I'm a fan of most people.

Or maybe LOVE devs are just that good.

bobbyjones
Party member
Posts: 720
Joined: Sat Apr 26, 2014 7:46 pm

Re: Lua Neural Network

Post by bobbyjones » Sun May 19, 2019 4:33 am

caralse wrote:
Fri May 17, 2019 9:52 am
Hi! I wrote this code using your Network but it doesn't work.
What am I missing?

Code: Select all

local NeuralNetwork = require("lnn")
math.randomseed(os.time())
local nn = NeuralNetwork.create(2, 1, 2, 2, 0.3)
local training_data = {
	{
		inputs = {0, 1},
		target = {1}
	},
	{
		inputs = {1, 1},
		target = {0}
	},
	{
		inputs = {1, 0},
		target = {1}
	},
	{
		inputs = {0, 0},
		target = {0}
	}
}

for i = 1, 2000 do
	local data = training_data[math.random(#training_data)]
	nn:backwardPropagate(data.inputs, data.target)
end
print(nn:forwardPropagate({0, 1})[1])
print(nn:forwardPropagate({1, 1})[1])
print(nn:forwardPropagate({0, 0})[1])
print(nn:forwardPropagate({1, 0})[1])
That just prints 1.
I pushed a fix to my repo. The softmax function didn't account for a singular output. Also, you have to up the training cycles to a much higher quantity if you want the neural net to output a 1. You can also play with the learning rate and etc.
Do you frequently have great ideas but immediately lose them? Check out the MVP for my website called IdeaVault. It is designed to solve that problem. Desktop browsers only currently.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests