stats making and reading files
This commit is contained in:
parent
2b6d093c0d
commit
5d54ccd751
47
stats-cm.py
Normal file
47
stats-cm.py
Normal file
@ -0,0 +1,47 @@
|
||||
from m import *
|
||||
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
def __prep_conf_matr(data):
|
||||
output_matrix = np.zeros([2, 2])
|
||||
|
||||
for p, r in zip(*data):
|
||||
print(p, r)
|
||||
output_matrix[np.argmax(p)][np.argmax(r)] += 1
|
||||
|
||||
return output_matrix
|
||||
|
||||
|
||||
def __plot_conf_matr(data):
|
||||
matr = __prep_conf_matr(data)
|
||||
|
||||
_, ax = plt.subplots()
|
||||
|
||||
ax.matshow(matr, cmap = plt.cm.Blues)
|
||||
|
||||
for i, x in enumerate(matr):
|
||||
for j, y in enumerate(x):
|
||||
ax.text(i,
|
||||
j,
|
||||
str(round(y)),
|
||||
va = "center",
|
||||
ha = "center")
|
||||
|
||||
plt.show()
|
||||
|
||||
ds = tf.keras.preprocessing.image_dataset_from_directory(
|
||||
'../dataset-orig-aug-1-mini-1/',
|
||||
labels = 'inferred',
|
||||
label_mode = 'categorical',
|
||||
color_mode = 'rgb',
|
||||
image_size = (300, 300),
|
||||
batch_size = 32,
|
||||
verbose = True
|
||||
)
|
||||
|
||||
#ds_short = ds.take(1)
|
||||
|
||||
p = mod.predict(ds)
|
||||
r = np.concatenate([y for x, y in ds])
|
||||
|
||||
__plot_conf_matr([p, r])
|
||||
20
stats-generic.py
Normal file
20
stats-generic.py
Normal file
@ -0,0 +1,20 @@
|
||||
from m import *
|
||||
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
ds = tf.keras.preprocessing.image_dataset_from_directory(
|
||||
'../dataset-orig-aug-1-mini-1/',
|
||||
labels = 'inferred',
|
||||
label_mode = 'categorical',
|
||||
color_mode = 'rgb',
|
||||
image_size = (300, 300),
|
||||
batch_size = 32,
|
||||
verbose = True
|
||||
)
|
||||
|
||||
p = mod.predict(ds)
|
||||
r = np.concatenate([y for x, y in ds])
|
||||
|
||||
with open('results.txt', 'w') as f:
|
||||
for i in zip(p, r):
|
||||
f.write(f"{i[0][0]} {i[0][1]} {i[1][0]} {i[1][1]}\n")
|
||||
30
stats-other.py
Normal file
30
stats-other.py
Normal file
@ -0,0 +1,30 @@
|
||||
from m import *
|
||||
from sklearn.metrics import f1_score, precision_score, recall_score, accuracy_score
|
||||
|
||||
|
||||
ds = tf.keras.preprocessing.image_dataset_from_directory(
|
||||
'../dataset-orig-aug-1-mini-1/',
|
||||
labels = 'inferred',
|
||||
label_mode = 'categorical',
|
||||
color_mode = 'rgb',
|
||||
image_size = (300, 300),
|
||||
batch_size = 32,
|
||||
verbose = True
|
||||
)
|
||||
|
||||
p = []
|
||||
r = []
|
||||
|
||||
with open('results.txt', 'r') as f:
|
||||
for i in f.read().split('\n'):
|
||||
if i == '':
|
||||
continue
|
||||
|
||||
res = tuple(map(float, i.split()))
|
||||
p.append([res[0] > 0.5, res[1] > 0.5])
|
||||
r.append([res[2], res[3]])
|
||||
|
||||
print(f"Accuracy : {accuracy_score(p, r)}")
|
||||
print(f"Precision : {precision_score(p, r, average = 'micro')}")
|
||||
print(f"Recall : {recall_score(p, r, average = 'micro')}")
|
||||
print(f"F1 Score : {f1_score(p, r, average = 'micro')}")
|
||||
13
stats-plot-1.py
Normal file
13
stats-plot-1.py
Normal file
@ -0,0 +1,13 @@
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
ta = [0.5396, 0.6266, 0.7137, 0.6768, 0.7114, 0.7821, 0.7373, 0.6866, 0.5987, 0.6861, 0.7236, 0.7147]
|
||||
va = [0.4273, 0.4714, 0.4273, 0.4229, 0.4317, 0.4229, 0.5022, 0.4449, 0.5947, 0.7489, 0.5815, 0.7048]
|
||||
|
||||
x = [i+1 for i in range(12)]
|
||||
|
||||
plt.plot(x, ta)
|
||||
plt.plot(x, va)
|
||||
|
||||
plt.legend(["train_acc", "valid_acc"])
|
||||
|
||||
plt.show()
|
||||
Loading…
x
Reference in New Issue
Block a user