Compare commits
5 Commits
convolutio
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
57ab0af6b1 | ||
|
9b8c6ffea8 | ||
|
dbed51a2a0 | ||
|
5cdc7b52e1 | ||
|
dcddbd017f |
@ -1,2 +1,10 @@
|
|||||||
# PT21-22-Reseau-Neurones
|
# PT21-22-Reseau-Neurones
|
||||||
|
|
||||||
|
Cette librairie python permet de créer simplement un modèle de perceptron multicouche en choisissant les hyperparamètres suivants:
|
||||||
|
- Le nombre de couches
|
||||||
|
- Le nombre de neurones pour chaque couche
|
||||||
|
- Le learning rate
|
||||||
|
- Le batch size
|
||||||
|
- Le nombre d’époques
|
||||||
|
|
||||||
|
Il est également possible de donner un jeu de données supplémentaire afin de mesurer la précision du modèle à la fin de l'entraînement. Lorsqu’il n'y a que deux neurones d'entrées, il y a une option pour visualiser l’entraînement.
|
@ -1,5 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import matplotlib
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import matplotlib.animation as animation
|
import matplotlib.animation as animation
|
||||||
import pickle
|
import pickle
|
||||||
@ -93,7 +94,7 @@ class network:
|
|||||||
vizualisationFrame = np.empty((30, 30))
|
vizualisationFrame = np.empty((30, 30))
|
||||||
for x in range(30):
|
for x in range(30):
|
||||||
for y in range(30):
|
for y in range(30):
|
||||||
vizualisationFrame[x][y] = self.process(np.array([float(x), float(y)]))
|
vizualisationFrame[x][y] = self.process(np.array([float(x)/30, float(y)/30]))
|
||||||
vizualisationData.append([graph.imshow(vizualisationFrame, animated=True)])
|
vizualisationData.append([graph.imshow(vizualisationFrame, animated=True)])
|
||||||
|
|
||||||
inputBatches = [inputs[j:j+batchSize] for j in range(0, len(inputs), batchSize)]
|
inputBatches = [inputs[j:j+batchSize] for j in range(0, len(inputs), batchSize)]
|
||||||
@ -135,7 +136,7 @@ class network:
|
|||||||
print(self.accuracy(accuracyInputs, accuracyDesiredOutputs))
|
print(self.accuracy(accuracyInputs, accuracyDesiredOutputs))
|
||||||
|
|
||||||
if (visualize):
|
if (visualize):
|
||||||
ani = animation.ArtistAnimation(fig, vizualisationData, interval=100)
|
ani = animation.ArtistAnimation(fig, vizualisationData, interval=100, repeat_delay=1000)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
def __Error(self, layer, neuron):
|
def __Error(self, layer, neuron):
|
||||||
|
@ -14,7 +14,7 @@ class Sketchpad(tkinter.Canvas):
|
|||||||
self.bind("<B1-Motion>", self.add_line)
|
self.bind("<B1-Motion>", self.add_line)
|
||||||
self.PILImage = Image.new("F", (560, 560), 100)
|
self.PILImage = Image.new("F", (560, 560), 100)
|
||||||
self.draw = ImageDraw.Draw(self.PILImage)
|
self.draw = ImageDraw.Draw(self.PILImage)
|
||||||
self.MNISTNN = network.networkFromFile("MNISTtest2")
|
self.MNISTNN = network.networkFromFile("MNIST30epoch")
|
||||||
self.predictionLabel = predictionLabel
|
self.predictionLabel = predictionLabel
|
||||||
|
|
||||||
def add_line(self, event):
|
def add_line(self, event):
|
||||||
|
BIN
tests/flowerGardenData
Executable file
BIN
tests/flowerGardenData
Executable file
Binary file not shown.
17
tests/flowerGardenLearningVisualization.py
Executable file
17
tests/flowerGardenLearningVisualization.py
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/python3
|
||||||
|
from sys import path
|
||||||
|
path.insert(1, "..")
|
||||||
|
from sobek.network import network
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
with open("flowerGardenData", "rb") as file:
|
||||||
|
data = pickle.load(file)
|
||||||
|
|
||||||
|
trainPoints = data[0]
|
||||||
|
trainLabels = data[1]
|
||||||
|
|
||||||
|
myNetwork = network(2, 16, 1)
|
||||||
|
|
||||||
|
learningRate = 3.0
|
||||||
|
|
||||||
|
myNetwork.train(trainPoints, trainLabels, learningRate, batchSize=100, epochs=3000, visualize=True)
|
34
tests/generateSobekFlowerGarden.py
Executable file
34
tests/generateSobekFlowerGarden.py
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/python3
|
||||||
|
import random
|
||||||
|
import numpy as np
|
||||||
|
import math
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
trainPoints = []
|
||||||
|
trainLabels = []
|
||||||
|
|
||||||
|
random.seed(1216513)
|
||||||
|
|
||||||
|
for i in range(1000):
|
||||||
|
x = random.randint(-50, 50)
|
||||||
|
y = random.randint(-50, 50)
|
||||||
|
|
||||||
|
distance = math.sqrt(x**2 + y**2)
|
||||||
|
|
||||||
|
if (distance < 10 or 20 < distance < 30):
|
||||||
|
trainLabels.append(np.ones(1))
|
||||||
|
else :
|
||||||
|
trainLabels.append(np.zeros(1))
|
||||||
|
|
||||||
|
x = (x+50)/100
|
||||||
|
y = (y+50)/100
|
||||||
|
|
||||||
|
trainPoints.append(np.array([x, y]))
|
||||||
|
|
||||||
|
print(trainPoints[1])
|
||||||
|
print(trainLabels[1])
|
||||||
|
|
||||||
|
data = [trainPoints, trainLabels]
|
||||||
|
|
||||||
|
with open("flowerGardenData", "wb") as file:
|
||||||
|
pickle.dump(data, file)
|
Loading…
Reference in New Issue
Block a user