Commit 6e95146f authored by Guillaume RENTON's avatar Guillaume RENTON

Prise en compte de l'apprentissage des matrices de noeuds et d'aretes séparées

parent b3e85f33
......@@ -79,11 +79,13 @@ def compute_matrix_assignment(tuple_assignment,G1,G2,permutation):
i = liste_node_G1.index(assignment[0])
mat_assignment[i][j]=1
i = m+n-1
while np.amax(mat_assignment[i][:])==0:
mat_assignment[i][i]=1
i-=1
for i in range(len(mat_assignment[0])):
if np.amax(mat_assignment[i,:])==0:
for j in range(len(mat_assignment[1])):
if np.amax(mat_assignment[:,j])==0:
mat_assignment[i][j]=1
break
mat_assignment = mat_assignment[:,permutation[1]]
return mat_assignment
......
......@@ -104,13 +104,13 @@ def creerModel_GED(nbChannel, weights_path=None):
return model
def trainModel_GED(path, nbEpoch, weights_Recognizer):
def trainModel_GED(path, nbEpoch, weights_Recognizer, double = True):
with open(path + "base_app.p", "rb") as fp:
baseApp = pickle.load(fp, encoding="bytes")
with open(path + "base_valid.p", "rb") as fp:
baseValid = pickle.load(fp, encoding="bytes")
nbChannel = np.shape(baseApp[0][0])[2]
nbChannel = 2 if double else 1
model = creerModel_GED(nbChannel)
freq_save_weight = 10
......@@ -130,7 +130,12 @@ def trainModel_GED(path, nbEpoch, weights_Recognizer):
random.shuffle(baseApp)
for fileApp in baseApp:
n += 1
batch = np.expand_dims(fileApp[0], axis=0)
if double:
batch = np.expand_dims(fileApp[0], axis=0)
else:
batch = fileApp[0][:,:,0]+fileApp[0][:,:,1]
batch = np.expand_dims(batch, axis=0)
batch = np.expand_dims(batch, axis=-1)
label = np.array(fileApp[1])
label = np.expand_dims(label, axis=0)
......@@ -157,7 +162,13 @@ def trainModel_GED(path, nbEpoch, weights_Recognizer):
for fileValid in baseValid:
n = n + 1
batch = np.expand_dims(fileValid[0], axis=0)
if double:
batch = np.expand_dims(fileValid[0], axis=0)
else:
batch = fileValid[0][:,:,0]+fileValid[0][:,:,1]
batch = np.expand_dims(batch, axis=0)
batch = np.expand_dims(batch, axis=-1)
label = np.array(fileValid[1])
label = np.expand_dims(label, axis=0)
......@@ -177,15 +188,14 @@ def trainModel_GED(path, nbEpoch, weights_Recognizer):
model.save('weights/model_{}_{}.h5'.format(weights_Recognizer, epoch))
def trainModel_assignment(path, nbEpoch, weights_Recognizer, dataset_type = ""):
def trainModel_assignment(path, nbEpoch, weights_Recognizer, dataset_type = "", double = True):
with open(path + "base_app{}.p".format(dataset_type), "rb") as fp:
baseApp = pickle.load(fp, encoding="bytes")
with open(path + "base_valid{}.p".format(dataset_type), "rb") as fp:
baseValid = pickle.load(fp, encoding="bytes")
print(baseApp[0][0])
nbChannel = np.shape(baseApp[0][0])[2]
print(nbChannel)
nbChannel = 2 if double else 1
model = creerModel_assignment(2, nbChannel)
weights = [0.5, 0.5]
......@@ -207,7 +217,12 @@ def trainModel_assignment(path, nbEpoch, weights_Recognizer, dataset_type = ""):
random.shuffle(baseApp)
for fileApp in baseApp:
n += 1
batch = np.expand_dims(fileApp[0], axis=0)
if double:
batch = np.expand_dims(fileApp[0], axis=0)
else:
batch = fileApp[0][:,:,0]+fileApp[0][:,:,1]
batch = np.expand_dims(batch, axis=0)
batch = np.expand_dims(batch, axis=-1)
label = np.array(fileApp[4])
labelb = 1 - label
label = np.stack((label, labelb), axis=-1)
......@@ -242,8 +257,12 @@ def trainModel_assignment(path, nbEpoch, weights_Recognizer, dataset_type = ""):
n = 0;
for fileValid in baseValid:
n = n + 1
batch = np.expand_dims(fileValid[0], axis=0)
if double:
batch = np.expand_dims(fileValid[0], axis=0)
else:
batch = fileValid[0][:,:,0]+fileValid[0][:,:,1]
batch = np.expand_dims(batch, axis=0)
batch = np.expand_dims(batch, axis=-1)
label = np.array(fileValid[4])
labelb = 1 - label
label = np.stack((label, labelb), axis=-1)
......@@ -269,5 +288,5 @@ def trainModel_assignment(path, nbEpoch, weights_Recognizer, dataset_type = ""):
if __name__ == "__main__":
path = "../../../LETTER_HIGH/"
epoch = 500
trainModel_assignment(path, epoch, "test_letter_GED_double",dataset_type = "_little")
trainModel_GED(path, epoch, "test_letter_GED_double",dataset_type = "_little")
......@@ -75,14 +75,19 @@ def compute_matrix_BPGED(permutation):
mat = mat[:,permutation[1]]
return mat
def predict_assignment(path, weights):
with open(path + "base_test.p", "rb") as fp:
def predict_assignment(path, weights, double=True):
with open(path + "base_test_little.p", "rb") as fp:
basetest = pickle.load(fp, encoding="bytes")
print(len(basetest))
model = creerModel_assignment(2,weights)
model = creerModel_assignment(2,2,weights)
for test in basetest:
batch = np.expand_dims(test[0], axis=0)
if double:
batch = np.expand_dims(test[0], axis=0)
else:
batch = test[0][:,:,0]+test[0][:,:,1]
batch = np.expand_dims(batch, axis=0)
batch = np.expand_dims(batch, axis=-1)
print(test[0].shape)
value_approx = model.predict(batch)
value_approx=np.squeeze(value_approx)
......@@ -91,17 +96,21 @@ def predict_assignment(path, weights):
print(type(test[4]))
print(type(test[4][0][0]))
plt.subplot(221)
plt.imshow(np.squeeze(test[0]), cmap="Greys")
plt.subplot(222)
plt.imshow(compute_matrix_BPGED(test[5]), cmap="bwr")
plt.subplot(223)
plt.imshow(test[4], cmap="bwr")
plt.subplot(224)
plt.subplot(222)
plt.imshow(value_approx, cmap="bwr")
if double:
plt.subplot(223)
plt.imshow(np.squeeze(test[0][:,:,0]), cmap="Greys")
plt.subplot(224)
plt.imshow(np.squeeze(test[0][:,:,1]), cmap="Greys")
else:
plt.subplot(223)
plt.imshow(np.squeeze(test[0]), cmap="Greys")
plt.show()
if __name__ == "__main__":
t = time.time()
predict_GED("../../../LETTER_HIGH/", "weights/model_test_letter_GED_60.h5")
predict_assignment("../../../LETTER_HIGH/", "weights/model_test_letter_GED_double_20.h5")
print("Temps ecoule : ", time.time() - t)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment