Lua Neural Network

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

Lua Neural Network

Post by bobbyjones »

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 291 times
User avatar
dusoft
Party member
Posts: 482
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Lua Neural Network

Post by dusoft »

What's the code doing? I see some line only.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Lua Neural Network

Post by bobbyjones »

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.
caralse
Prole
Posts: 1
Joined: Fri May 17, 2019 9:47 am

Re: Lua Neural Network

Post by caralse »

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: 64
Joined: Mon Apr 02, 2018 3:31 pm

Re: Lua Neural Network

Post by yintercept »

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
Back in the saddle again.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Lua Neural Network

Post by bobbyjones »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests