training neural network ok, needs too much ram. Started implementation of the server

This commit is contained in:
arnaucode
2017-10-28 12:10:28 +02:00
parent 6c0b97dd98
commit 8068099897
26 changed files with 990 additions and 0 deletions

2
imagesToDataset/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
object
noobject

37
imagesToDataset/README.md Normal file
View File

@@ -0,0 +1,37 @@
# imagesToDataset
Gets all the images from the directories 'object' and 'noobject', and puts in a dataset file.
The dataset file is a dataset.data file that contains 2 columns:
- images arrays of pixels
- 0 or 1, depending if is from the 'noobject' or 'object' directory
First, install the libraries.
### install scikit-learn
http://scikit-learn.org/stable/install.html
pip install -U scikit-learn
### install scikit-image
http://scikit-image.org/download
pip install -U scikit-image
### install numpy
https://www.scipy.org/install.html
python -m pip install --upgrade pip
pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
### install Pillow
http://pillow.readthedocs.io/en/3.0.x/installation.html
(sudo) pip install Pillow
### install matplotlib
https://matplotlib.org/users/installing.html
python -mpip install -U pip
python -mpip install -U matplotlib
may need to install python-tk:
sudo apt-get install python-tk
## to run
python readDataset.py

BIN
imagesToDataset/dataset.npy Normal file

Binary file not shown.

47
imagesToDataset/main.py Normal file
View File

@@ -0,0 +1,47 @@
from os import walk
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image, ImageOps
#pixels, pixels of the output resizing images
size = 100, 100
def imgFileToData(path):
image = Image.open(path)
#resize the image
thumb = ImageOps.fit(image, size, Image.ANTIALIAS)
image_data = np.asarray(thumb).flatten()
'''
plt.plot(111)
plt.imshow(thumb)
plt.show()
'''
if len(image_data)!=30000:
print "possible future ERROR!"
print "len: " + str(len(image_data))
print "please, delete: " + path
return image_data
def getDirectoryFiles(path, imgClass):
images = []
for (dirpath, dirnames, filenames) in walk(path):
for filename in filenames:
#print filename
image_data = imgFileToData(path + "/" + filename)
images.append([image_data, imgClass])
return images
def asdf():
for index, (image, prediction) in enumerate(images_and_predictions[:4]):
plt.subplot(2, 4, index + 5)
plt.axis('off')
plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
plt.title('Prediction: %i' % prediction)
objects = getDirectoryFiles("object", 1)
noobjects = getDirectoryFiles("noobject", 0)
dataset = np.concatenate((objects, noobjects), axis=0)
np.save('dataset.npy', dataset)

View File

@@ -0,0 +1,16 @@
import matplotlib.pyplot as plt
import numpy as np
from random import randint
dataset = np.load('dataset.npy')
n = randint(0, len(dataset))
plt.plot(111)
plt.axis('off')
plt.imshow(dataset[n][0])
plt.title('class: ' + str(dataset[n][1]))
plt.show()