Neural Network
70
NeuralNetwork.md
Normal file
@ -0,0 +1,70 @@
|
||||
# DSZI_Survival - Sieć Neuronowa
|
||||
### Autor: Jonathan Spaczyński
|
||||
|
||||
## Cel zastosowania w projekcie
|
||||
W projekcie DSZI_Survival sieć neuronowa użyta jest do podejmowania decyzji przez agenta.
|
||||
Decyzja polega na rozpoznawaniu zdjęć owoców (jabłka i gruszki). W przypadku nie rozpoznania owocu przez
|
||||
agenta, dochodzi do zatrucia i agent umiera/przegrywa.
|
||||
|
||||
## Przygotowanie danych
|
||||
|
||||
* **Krok 1** Przechowywane zdjęcia owoców muszą przejść przez proces zamiany zdjęcia (.jpg) na dane, które
|
||||
mogą być wykorzystane przez sieć neuronową.
|
||||
|
||||
```python
|
||||
CATEGORIES = ["Apple", "Pear"]
|
||||
IMG_SIZE = 64
|
||||
|
||||
training_data = []
|
||||
|
||||
|
||||
def create_training_data():
|
||||
for category in CATEGORIES:
|
||||
path = os.path.join(DATADIR, category)
|
||||
class_num = CATEGORIES.index(category)
|
||||
for img in os.listdir(path):
|
||||
try:
|
||||
img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
|
||||
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
|
||||
training_data.append([new_array, class_num])
|
||||
except Exception as e:
|
||||
pass
|
||||
```
|
||||
zdjęcia są przechowywane w tablicy training_data wraz z klasyfikacją (class_num) odpowiadającą jakim typem owocu jest zdjęcie
|
||||
|
||||
* **Krok 2** Bardzo ważnym krokiem jest pomieszanie danych. W przeciwnym wypadku nasz model po ciągłym otrzymywanie danych
|
||||
reprezentujących tylko jedną kategorię owoców mógłby się wyuczyć, aby tylko zgadywać tą kategorię.
|
||||
```python
|
||||
random.shuffle(training_data)
|
||||
```
|
||||
* **Krok 3** Ostatnim krokiem jest zaktualizowanie danych w taki sposób żeby były z przedziału
|
||||
od 0 d 255 (reprezentacja koloru danego pixela)
|
||||
```python
|
||||
X = X / 255.0
|
||||
```
|
||||
## Kilka słów na temat danych
|
||||
* **Ilość Danych** Do trenowania modelu wykorzystałem 8568 zdjęć gruszek i jabłek
|
||||
z czego mniej więcej połowa danych była jednym z typów ww. owoców, a druga połowa
|
||||
reprezentowała pozostałą kategorią
|
||||
* **Dane wykorzystane do obliczenia skutecznośći** stanowiły małą i oddzielną część danych wykorzystanych do trenowania.
|
||||
## Model
|
||||
* **Dane wejściowe:** Dane o kształcie 64x64 reprezentujące pixele w zdjęciach owoców
|
||||
* **Warstwa ukryta:** Składająca się z 128 "neuronów" wykorzystującą sigmoid jako funkcję aktywacyjną
|
||||
* **Warstwa wyjściowa:** Składająca się z 2 "neuronów" reprezentujących gruszkę i jabłko
|
||||
* **Stała ucząca:** 0.001
|
||||
|
||||
```python
|
||||
model = tf.keras.Sequential([
|
||||
tf.keras.layers.Flatten(input_shape=(64, 64)),
|
||||
tf.keras.layers.Dense(128, activation=tf.nn.sigmoid),
|
||||
tf.keras.layers.Dense(2, activation=tf.nn.sigmoid)
|
||||
])
|
||||
|
||||
model.compile(tf.keras.optimizers.Adam(lr=0.001),
|
||||
loss="sparse_categorical_crossentropy",
|
||||
metrics=["accuracy"])
|
||||
```
|
||||
## Osiągniecia modelu
|
||||
* **Trafność:** 86.4%
|
||||
* **Strata:** 0.312
|
||||
|
BIN
data/AI_data/Nn_images/Apple/1 (115).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Apple/1 (151).jpg
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
data/AI_data/Nn_images/Apple/1 (27).jpg
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
data/AI_data/Nn_images/Apple/1 (37).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Apple/1 (53).jpg
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
data/AI_data/Nn_images/Apple/1 (8).jpg
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
data/AI_data/Nn_images/Apple/1 (84).jpg
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
data/AI_data/Nn_images/Apple/2 (129).jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
data/AI_data/Nn_images/Apple/2 (19).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Apple/2 (59).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Apple/2 (94).jpg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
data/AI_data/Nn_images/Apple/3 (10).jpg
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
data/AI_data/Nn_images/Apple/3 (130).jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
data/AI_data/Nn_images/Apple/3 (35).jpg
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
data/AI_data/Nn_images/Apple/3 (69).jpg
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
data/AI_data/Nn_images/Apple/3 (98).jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
data/AI_data/Nn_images/Apple/37_100.jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
data/AI_data/Nn_images/Apple/4 (129).jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
data/AI_data/Nn_images/Apple/4 (163).jpg
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
data/AI_data/Nn_images/Apple/4 (36).jpg
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
data/AI_data/Nn_images/Apple/4 (4).jpg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
data/AI_data/Nn_images/Apple/4 (64).jpg
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
data/AI_data/Nn_images/Apple/4 (95).jpg
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
data/AI_data/Nn_images/Apple/5 (129).jpg
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
data/AI_data/Nn_images/Apple/5 (33).jpg
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
data/AI_data/Nn_images/Apple/5 (61).jpg
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
data/AI_data/Nn_images/Apple/5 (92).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Apple/6 (104).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Apple/6 (132).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Apple/6 (163).jpg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
data/AI_data/Nn_images/Apple/6 (42).jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
data/AI_data/Nn_images/Apple/6 (5).jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
data/AI_data/Nn_images/Apple/6 (76).jpg
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
data/AI_data/Nn_images/Apple/7 (114).jpg
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
data/AI_data/Nn_images/Apple/7 (145).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Apple/7 (24).jpg
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
data/AI_data/Nn_images/Apple/7 (49).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Apple/7 (77).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Apple/8 (115).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Apple/8 (144).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Apple/8 (21).jpg
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
data/AI_data/Nn_images/Apple/8 (46).jpg
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
data/AI_data/Nn_images/Apple/8 (65).jpg
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
data/AI_data/Nn_images/Apple/8 (84).jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
data/AI_data/Nn_images/Apple/8 (99).jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
data/AI_data/Nn_images/Apple/84_100.jpg
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
data/AI_data/Nn_images/Apple/9 (123).jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
data/AI_data/Nn_images/Apple/9 (151).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Apple/9 (161).jpg
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
data/AI_data/Nn_images/Apple/9 (36).jpg
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
data/AI_data/Nn_images/Apple/9 (64).jpg
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
data/AI_data/Nn_images/Apple/9 (8).jpg
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
data/AI_data/Nn_images/Apple/9 (92).jpg
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
data/AI_data/Nn_images/Apple/r_327_100.jpg
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
data/AI_data/Nn_images/Apple/r_5_100.jpg
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
data/AI_data/Nn_images/Apple/r_97_100.jpg
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
data/AI_data/Nn_images/Pear/0_100.jpg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
data/AI_data/Nn_images/Pear/1 (12).jpg
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
data/AI_data/Nn_images/Pear/1 (130).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Pear/1 (164).jpg
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
data/AI_data/Nn_images/Pear/1 (2).jpg
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
data/AI_data/Nn_images/Pear/1 (43).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
data/AI_data/Nn_images/Pear/1 (71).jpg
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
data/AI_data/Nn_images/Pear/1 (99).jpg
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (116).jpg
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (13).jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (144).jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (172).jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (197).jpg
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (225).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (41).jpg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (54).jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
data/AI_data/Nn_images/Pear/2 (91).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Pear/250_100.jpg
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (114).jpg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (142).jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (170).jpg
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (18).jpg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (204).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (219).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (220).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (52).jpg
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
data/AI_data/Nn_images/Pear/3 (86).jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
data/AI_data/Nn_images/Pear/4 (1).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
data/AI_data/Nn_images/Pear/4 (133).jpg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
data/AI_data/Nn_images/Pear/4 (28).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
data/AI_data/Nn_images/Pear/4 (62).jpg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
data/AI_data/Nn_images/Pear/4 (99).jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
data/AI_data/Nn_images/Pear/5 (125).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
data/AI_data/Nn_images/Pear/5 (153).jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
data/AI_data/Nn_images/Pear/5 (190).jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
data/AI_data/Nn_images/Pear/5 (218).jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
data/AI_data/Nn_images/Pear/5 (32).jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
data/AI_data/Nn_images/Pear/5 (4).jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
data/AI_data/Nn_images/Pear/5 (63).jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
data/AI_data/Nn_images/Pear/5 (94).jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
data/AI_data/Nn_images/Pear/6 (117).jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
data/AI_data/Nn_images/Pear/6 (145).jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
data/AI_data/Nn_images/Pear/6 (170).jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |