Spaces:
Running
Running
correction of double in XML
Browse files- .gitignore +4 -0
- app.py +3 -1
- modules/eval.py +32 -27
- modules/toXML.py +14 -8
.gitignore
CHANGED
@@ -17,3 +17,7 @@ temp.jpg
|
|
17 |
Evaluation.ipynb
|
18 |
|
19 |
study/
|
|
|
|
|
|
|
|
|
|
17 |
Evaluation.ipynb
|
18 |
|
19 |
study/
|
20 |
+
|
21 |
+
result_bpmn.bpmn
|
22 |
+
|
23 |
+
BPMN_creation.ipynb
|
app.py
CHANGED
@@ -245,6 +245,8 @@ def load_models():
|
|
245 |
st.session_state.model_arrow = model_arrow
|
246 |
st.session_state.model_object = model_object
|
247 |
|
|
|
|
|
248 |
# Function to prepare the image for processing
|
249 |
def prepare_image(image, pad=True, new_size=(1333, 1333)):
|
250 |
original_size = image.size
|
@@ -415,7 +417,7 @@ def main():
|
|
415 |
# Load the models using the defined function
|
416 |
if 'model_object' not in st.session_state or 'model_arrow' not in st.session_state:
|
417 |
clear_memory()
|
418 |
-
load_models()
|
419 |
|
420 |
model_arrow = st.session_state.model_arrow
|
421 |
model_object = st.session_state.model_object
|
|
|
245 |
st.session_state.model_arrow = model_arrow
|
246 |
st.session_state.model_object = model_object
|
247 |
|
248 |
+
return model_object, model_arrow
|
249 |
+
|
250 |
# Function to prepare the image for processing
|
251 |
def prepare_image(image, pad=True, new_size=(1333, 1333)):
|
252 |
original_size = image.size
|
|
|
417 |
# Load the models using the defined function
|
418 |
if 'model_object' not in st.session_state or 'model_arrow' not in st.session_state:
|
419 |
clear_memory()
|
420 |
+
_, _ = load_models()
|
421 |
|
422 |
model_arrow = st.session_state.model_arrow
|
423 |
model_object = st.session_state.model_object
|
modules/eval.py
CHANGED
@@ -279,47 +279,51 @@ def create_links(keypoints, boxes, labels, class_dict):
|
|
279 |
|
280 |
return links, best_points
|
281 |
|
282 |
-
def correction_labels(boxes, labels, class_dict, pool_dict, flow_links):
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
for pool_index, elements in pool_dict.items():
|
284 |
print(f"Pool {pool_index} contains elements: {elements}")
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
if id1 is not None and id2 is not None:
|
290 |
-
#
|
291 |
if id1 in elements and id2 in elements:
|
292 |
-
#
|
293 |
-
if labels[id1]
|
294 |
-
print('
|
295 |
-
labels[i]=
|
296 |
else:
|
297 |
continue
|
298 |
elif id1 not in elements and id2 not in elements:
|
299 |
continue
|
300 |
else:
|
301 |
-
print('
|
302 |
-
labels[i]=
|
303 |
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
if labels[i] == list(class_dict.values()).index('dataAssociation'):
|
309 |
-
id1, id2 = flow_links[i]
|
310 |
-
if (id1 and id2) is not None:
|
311 |
label1 = labels[id1]
|
312 |
label2 = labels[id2]
|
313 |
-
|
|
|
314 |
continue
|
315 |
else:
|
316 |
-
print('
|
317 |
-
labels[i]=
|
318 |
-
|
319 |
|
320 |
return labels, flow_links
|
321 |
|
322 |
|
|
|
323 |
def last_correction(boxes, labels, scores, keypoints, links, best_points, pool_dict):
|
324 |
|
325 |
#delete pool that are have only messageFlow on it
|
@@ -398,6 +402,11 @@ def full_prediction(model_object, model_arrow, image, score_threshold=0.5, iou_t
|
|
398 |
labels, flow_links = correction_labels(boxes, labels, class_dict, pool_dict, flow_links)
|
399 |
#give a link to event to allow the creation of the BPMN id with start, indermediate and end event
|
400 |
flow_links = give_link_to_element(flow_links, labels)
|
|
|
|
|
|
|
|
|
|
|
401 |
|
402 |
boxes,labels,scores,keypoints,flow_links,best_points,pool_dict = last_correction(boxes,labels,scores,keypoints,flow_links,best_points, pool_dict)
|
403 |
|
@@ -425,10 +434,6 @@ def full_prediction(model_object, model_arrow, image, score_threshold=0.5, iou_t
|
|
425 |
# give a unique BPMN id to each element
|
426 |
data = create_BPMN_id(data)
|
427 |
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
return image, data
|
433 |
|
434 |
def evaluate_model_by_class(pred_boxes, true_boxes, pred_labels, true_labels, model_dict, iou_threshold=0.5):
|
|
|
279 |
|
280 |
return links, best_points
|
281 |
|
282 |
+
def correction_labels(boxes, labels, class_dict, pool_dict, flow_links):
|
283 |
+
sequence_flow_index = list(class_dict.values()).index('sequenceFlow')
|
284 |
+
message_flow_index = list(class_dict.values()).index('messageFlow')
|
285 |
+
data_association_index = list(class_dict.values()).index('dataAssociation')
|
286 |
+
data_object_index = list(class_dict.values()).index('dataObject')
|
287 |
+
data_store_index = list(class_dict.values()).index('dataStore')
|
288 |
+
|
289 |
for pool_index, elements in pool_dict.items():
|
290 |
print(f"Pool {pool_index} contains elements: {elements}")
|
291 |
+
|
292 |
+
# Check if the label sequenceFlow or messageFlow is good
|
293 |
+
for i, (id1, id2) in enumerate(flow_links):
|
294 |
+
if labels[i] in {sequence_flow_index, message_flow_index}:
|
295 |
if id1 is not None and id2 is not None:
|
296 |
+
# Check if each link is in the same pool
|
297 |
if id1 in elements and id2 in elements:
|
298 |
+
# Check if the link is between a dataObject or a dataStore
|
299 |
+
if labels[id1] in {data_object_index, data_store_index} or labels[id2] in {data_object_index, data_store_index}:
|
300 |
+
print('Change the link from sequenceFlow/messageFlow to dataAssociation')
|
301 |
+
labels[i] = data_association_index
|
302 |
else:
|
303 |
continue
|
304 |
elif id1 not in elements and id2 not in elements:
|
305 |
continue
|
306 |
else:
|
307 |
+
print('Change the link from sequenceFlow to messageFlow')
|
308 |
+
labels[i] = message_flow_index
|
309 |
|
310 |
+
# Check if dataAssociation is connected to a dataObject
|
311 |
+
for i, (id1, id2) in enumerate(flow_links):
|
312 |
+
if labels[i] == data_association_index:
|
313 |
+
if id1 is not None and id2 is not None:
|
|
|
|
|
|
|
314 |
label1 = labels[id1]
|
315 |
label2 = labels[id2]
|
316 |
+
print(label1, label2)
|
317 |
+
if data_object_index in {label1, label2} or data_store_index in {label1, label2}:
|
318 |
continue
|
319 |
else:
|
320 |
+
print('Change the link from dataAssociation to messageFlow')
|
321 |
+
labels[i] = message_flow_index
|
|
|
322 |
|
323 |
return labels, flow_links
|
324 |
|
325 |
|
326 |
+
|
327 |
def last_correction(boxes, labels, scores, keypoints, links, best_points, pool_dict):
|
328 |
|
329 |
#delete pool that are have only messageFlow on it
|
|
|
402 |
labels, flow_links = correction_labels(boxes, labels, class_dict, pool_dict, flow_links)
|
403 |
#give a link to event to allow the creation of the BPMN id with start, indermediate and end event
|
404 |
flow_links = give_link_to_element(flow_links, labels)
|
405 |
+
|
406 |
+
#change every datastore to dataobject [TO DO: change it to make the dataStore work]
|
407 |
+
for i in range(len(labels)):
|
408 |
+
if labels[i] == list(class_dict.values()).index('dataStore'):
|
409 |
+
labels[i] = list(class_dict.values()).index('dataObject')
|
410 |
|
411 |
boxes,labels,scores,keypoints,flow_links,best_points,pool_dict = last_correction(boxes,labels,scores,keypoints,flow_links,best_points, pool_dict)
|
412 |
|
|
|
434 |
# give a unique BPMN id to each element
|
435 |
data = create_BPMN_id(data)
|
436 |
|
|
|
|
|
|
|
|
|
437 |
return image, data
|
438 |
|
439 |
def evaluate_model_by_class(pred_boxes, true_boxes, pred_labels, true_labels, model_dict, iou_threshold=0.5):
|
modules/toXML.py
CHANGED
@@ -22,7 +22,8 @@ def create_BPMN_id(data):
|
|
22 |
'pool': 1,
|
23 |
'dataObject': 1,
|
24 |
'dataStore': 1,
|
25 |
-
'timerEvent': 1
|
|
|
26 |
}
|
27 |
|
28 |
BPMN_name = [class_dict[label] for label in data['labels']]
|
@@ -40,7 +41,8 @@ def create_BPMN_id(data):
|
|
40 |
'dataAssociation': 'dataAssociation',
|
41 |
'pool': 'pool',
|
42 |
'dataStore': 'dataStore',
|
43 |
-
'timerEvent': 'timerEvent'
|
|
|
44 |
}.get(Bpmn_id, None)
|
45 |
|
46 |
if key:
|
@@ -156,7 +158,7 @@ def create_bpmn_object(process, bpmnplane, text_mapping, definitions, size, data
|
|
156 |
dataObject_idx = links[dataAssociation_idx][0]
|
157 |
dataObject_name = elements[dataObject_idx]
|
158 |
dataObject_ref = f'DataObjectReference_{dataObject_name.split("_")[1]}'
|
159 |
-
sub_element = ET.SubElement(element, 'bpmn:dataInputAssociation', id=f'
|
160 |
ET.SubElement(sub_element, 'bpmn:sourceRef').text = dataObject_ref
|
161 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], dataAssociation_idx, dataObject_name, element_id)
|
162 |
|
@@ -165,7 +167,7 @@ def create_bpmn_object(process, bpmnplane, text_mapping, definitions, size, data
|
|
165 |
dataObject_idx = links[dataAssociation_idx][1]
|
166 |
dataObject_name = elements[dataObject_idx]
|
167 |
dataObject_ref = f'DataObjectReference_{dataObject_name.split("_")[1]}'
|
168 |
-
sub_element = ET.SubElement(element, 'bpmn:dataOutputAssociation', id=f'
|
169 |
ET.SubElement(sub_element, 'bpmn:targetRef').text = dataObject_ref
|
170 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], dataAssociation_idx, element_id, dataObject_name)
|
171 |
|
@@ -182,23 +184,27 @@ def create_bpmn_object(process, bpmnplane, text_mapping, definitions, size, data
|
|
182 |
element = ET.SubElement(process, 'bpmn:endEvent', id=element_id, name=text_mapping[element_id])
|
183 |
|
184 |
status, datasAssociation_idx = check_data_association(i, data['links'], data['labels'], keep_elements)
|
|
|
185 |
if len(status) != 0:
|
|
|
186 |
for state, dataAssociation_idx in zip(status, datasAssociation_idx):
|
187 |
# Handle Data Input Association
|
188 |
if state == 'input':
|
|
|
189 |
dataObject_idx = links[dataAssociation_idx][0]
|
190 |
dataObject_name = elements[dataObject_idx]
|
191 |
dataObject_ref = f'DataObjectReference_{dataObject_name.split("_")[1]}'
|
192 |
-
sub_element = ET.SubElement(element, 'bpmn:dataInputAssociation', id=f'
|
193 |
ET.SubElement(sub_element, 'bpmn:sourceRef').text = dataObject_ref
|
194 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], dataAssociation_idx, dataObject_name, element_id)
|
195 |
|
196 |
# Handle Data Output Association
|
197 |
elif state == 'output':
|
|
|
198 |
dataObject_idx = links[dataAssociation_idx][1]
|
199 |
dataObject_name = elements[dataObject_idx]
|
200 |
dataObject_ref = f'DataObjectReference_{dataObject_name.split("_")[1]}'
|
201 |
-
sub_element = ET.SubElement(element, 'bpmn:dataOutputAssociation', id=f'
|
202 |
ET.SubElement(sub_element, 'bpmn:targetRef').text = dataObject_ref
|
203 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], dataAssociation_idx, element_id, dataObject_name)
|
204 |
|
@@ -221,14 +227,14 @@ def create_bpmn_object(process, bpmnplane, text_mapping, definitions, size, data
|
|
221 |
if state == 'input' :
|
222 |
gateway_idx = links[link_idx][0]
|
223 |
gateway_name = elements[gateway_idx]
|
224 |
-
sub_element = ET.SubElement(element, 'bpmn:eventBasedGateway', id=f'
|
225 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], i, gateway_name, element_id)
|
226 |
|
227 |
# Handle Data Output Association
|
228 |
elif state == 'output':
|
229 |
gateway_idx = links[link_idx][1]
|
230 |
gateway_name = elements[gateway_idx]
|
231 |
-
sub_element = ET.SubElement(element, 'bpmn:eventBasedGateway', id=f'
|
232 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], i, element_id, gateway_name)
|
233 |
|
234 |
|
|
|
22 |
'pool': 1,
|
23 |
'dataObject': 1,
|
24 |
'dataStore': 1,
|
25 |
+
'timerEvent': 1,
|
26 |
+
'eventBasedGateway': 1
|
27 |
}
|
28 |
|
29 |
BPMN_name = [class_dict[label] for label in data['labels']]
|
|
|
41 |
'dataAssociation': 'dataAssociation',
|
42 |
'pool': 'pool',
|
43 |
'dataStore': 'dataStore',
|
44 |
+
'timerEvent': 'timerEvent',
|
45 |
+
'eventBasedGateway': 'eventBasedGateway'
|
46 |
}.get(Bpmn_id, None)
|
47 |
|
48 |
if key:
|
|
|
158 |
dataObject_idx = links[dataAssociation_idx][0]
|
159 |
dataObject_name = elements[dataObject_idx]
|
160 |
dataObject_ref = f'DataObjectReference_{dataObject_name.split("_")[1]}'
|
161 |
+
sub_element = ET.SubElement(element, 'bpmn:dataInputAssociation', id=f'dataInAsso_{dataAssociation_idx}_{dataObject_ref.split("_")[1]}')
|
162 |
ET.SubElement(sub_element, 'bpmn:sourceRef').text = dataObject_ref
|
163 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], dataAssociation_idx, dataObject_name, element_id)
|
164 |
|
|
|
167 |
dataObject_idx = links[dataAssociation_idx][1]
|
168 |
dataObject_name = elements[dataObject_idx]
|
169 |
dataObject_ref = f'DataObjectReference_{dataObject_name.split("_")[1]}'
|
170 |
+
sub_element = ET.SubElement(element, 'bpmn:dataOutputAssociation', id=f'dataOutAsso_{dataAssociation_idx}_{dataObject_ref.split("_")[1]}')
|
171 |
ET.SubElement(sub_element, 'bpmn:targetRef').text = dataObject_ref
|
172 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], dataAssociation_idx, element_id, dataObject_name)
|
173 |
|
|
|
184 |
element = ET.SubElement(process, 'bpmn:endEvent', id=element_id, name=text_mapping[element_id])
|
185 |
|
186 |
status, datasAssociation_idx = check_data_association(i, data['links'], data['labels'], keep_elements)
|
187 |
+
print('status', status, datasAssociation_idx, element_id)
|
188 |
if len(status) != 0:
|
189 |
+
print('ici')
|
190 |
for state, dataAssociation_idx in zip(status, datasAssociation_idx):
|
191 |
# Handle Data Input Association
|
192 |
if state == 'input':
|
193 |
+
print('input')
|
194 |
dataObject_idx = links[dataAssociation_idx][0]
|
195 |
dataObject_name = elements[dataObject_idx]
|
196 |
dataObject_ref = f'DataObjectReference_{dataObject_name.split("_")[1]}'
|
197 |
+
sub_element = ET.SubElement(element, 'bpmn:dataInputAssociation', id=f'dataInAsso_{dataAssociation_idx}_{dataObject_ref.split("_")[1]}')
|
198 |
ET.SubElement(sub_element, 'bpmn:sourceRef').text = dataObject_ref
|
199 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], dataAssociation_idx, dataObject_name, element_id)
|
200 |
|
201 |
# Handle Data Output Association
|
202 |
elif state == 'output':
|
203 |
+
print('output')
|
204 |
dataObject_idx = links[dataAssociation_idx][1]
|
205 |
dataObject_name = elements[dataObject_idx]
|
206 |
dataObject_ref = f'DataObjectReference_{dataObject_name.split("_")[1]}'
|
207 |
+
sub_element = ET.SubElement(element, 'bpmn:dataOutputAssociation', id=f'dataOutAsso_{dataAssociation_idx}_{dataObject_ref.split("_")[1]}')
|
208 |
ET.SubElement(sub_element, 'bpmn:targetRef').text = dataObject_ref
|
209 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], dataAssociation_idx, element_id, dataObject_name)
|
210 |
|
|
|
227 |
if state == 'input' :
|
228 |
gateway_idx = links[link_idx][0]
|
229 |
gateway_name = elements[gateway_idx]
|
230 |
+
sub_element = ET.SubElement(element, 'bpmn:eventBasedGateway', id=f'eventBasedGateway_{link_idx}_{gateway_name.split("_")[1]}')
|
231 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], i, gateway_name, element_id)
|
232 |
|
233 |
# Handle Data Output Association
|
234 |
elif state == 'output':
|
235 |
gateway_idx = links[link_idx][1]
|
236 |
gateway_name = elements[gateway_idx]
|
237 |
+
sub_element = ET.SubElement(element, 'bpmn:eventBasedGateway', id=f'eventBasedGateway_{link_idx}_{gateway_name.split("_")[1]}')
|
238 |
create_data_Association(bpmnplane, data, size, sub_element.attrib['id'], i, element_id, gateway_name)
|
239 |
|
240 |
|