-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfish.py
executable file
·62 lines (49 loc) · 2 KB
/
fish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
import numpy as np
import pandas as pd
import cv2
from sklearn.model_selection import train_test_split
import image_formatter
import model
def load(width=32, height=32):
df = pd.read_csv("datasets/fish/final_all_index.txt", sep="=", header=None)
files = df.iloc[:, 3]
all_labels = df.iloc[:, 0]
img_types = df.iloc[:, 2]
images = []
labels = []
for row, file in enumerate(files):
if img_types[row] == "insitu":
img = cv2.imread("datasets/fish/images/cropped/" + file + ".png")
img = cv2.resize(img, (width, height))
images.append(img)
labels.append(all_labels[row])
images = np.array(images)
labels = np.array(labels)
return train_test_split(images, labels, test_size=0.2, random_state=42)
def main():
loss = {}
accuracy = {}
val_loss = {}
val_accuracy = {}
(orig_train_images, orig_test_images,
train_labels, test_labels) = load()
out_size = max(train_labels.max(), test_labels.max())+1
for color_space in image_formatter.color_spaces:
train_images = image_formatter.convert_images(orig_train_images,
color_space)
test_images = image_formatter.convert_images(orig_test_images,
color_space)
fish_model = model.model(out_size)
history = fish_model.fit(train_images, train_labels, epochs=10,
validation_data=(test_images, test_labels))
loss["fish_" + color_space] = history.history["loss"]
val_loss["fish_" + color_space] = history.history["val_loss"]
accuracy["fish_" + color_space] = history.history["accuracy"]
val_accuracy["fish_" + color_space] = history.history["val_accuracy"]
loss_df = pd.DataFrame(loss)
val_loss_df = pd.DataFrame(val_loss)
accuracy_df = pd.DataFrame(accuracy)
val_accuracy_df = pd.DataFrame(val_accuracy)
if __name__ == "__main__":
main()