Update Model/MultimodelNER/VLSP2016/MNER_2016.py
Browse files
Model/MultimodelNER/VLSP2016/MNER_2016.py
CHANGED
@@ -23,7 +23,7 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
23 |
|
24 |
|
25 |
net = getattr(resnet, 'resnet152')()
|
26 |
-
net.load_state_dict(torch.load(os.path.join('
|
27 |
encoder = myResnet(net, True, device)
|
28 |
def process_text(text):
|
29 |
# Loại bỏ dấu cách thừa và dấu cách ở đầu và cuối văn bản
|
@@ -37,8 +37,8 @@ def show_mner_2016():
|
|
37 |
multimodal_text = process_text(multimodal_text) # Xử lý văn bản
|
38 |
image = st.file_uploader("Upload an image (only jpg):", type=["jpg"])
|
39 |
if st.button("Process Multimodal NER"):
|
40 |
-
save_image = '
|
41 |
-
save_txt = '
|
42 |
image_name = image.name
|
43 |
save_uploaded_image(image, save_image)
|
44 |
convert_text_to_txt(multimodal_text, save_txt)
|
@@ -46,7 +46,7 @@ def show_mner_2016():
|
|
46 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
47 |
|
48 |
bert_model='vinai/phobert-base-v2'
|
49 |
-
output_dir='
|
50 |
output_model_file = os.path.join(output_dir, WEIGHTS_NAME)
|
51 |
output_encoder_file = os.path.join(output_dir, "pytorch_encoder.bin")
|
52 |
processor = MNERProcessor_2016()
|
@@ -70,7 +70,7 @@ def show_mner_2016():
|
|
70 |
trans_matrix[6, 12] = 1
|
71 |
tokenizer = AutoTokenizer.from_pretrained(bert_model, do_lower_case=False)
|
72 |
model_umt, encoder_umt = load_model(output_model_file, output_encoder_file, encoder,num_labels,auxnum_labels)
|
73 |
-
eval_examples = get_test_examples_predict('
|
74 |
|
75 |
y_pred, a = predict(model_umt, encoder_umt, eval_examples, tokenizer, device,save_image,trans_matrix)
|
76 |
formatted_output = format_predictions(a, y_pred[0])
|
|
|
23 |
|
24 |
|
25 |
net = getattr(resnet, 'resnet152')()
|
26 |
+
net.load_state_dict(torch.load(os.path.join('Model/Resnet/', 'resnet152.pth')))
|
27 |
encoder = myResnet(net, True, device)
|
28 |
def process_text(text):
|
29 |
# Loại bỏ dấu cách thừa và dấu cách ở đầu và cuối văn bản
|
|
|
37 |
multimodal_text = process_text(multimodal_text) # Xử lý văn bản
|
38 |
image = st.file_uploader("Upload an image (only jpg):", type=["jpg"])
|
39 |
if st.button("Process Multimodal NER"):
|
40 |
+
save_image = 'Model/MultimodelNER/VLSP2016/Image'
|
41 |
+
save_txt = 'Model/MultimodelNER/VLSP2016/Filetxt/test.txt'
|
42 |
image_name = image.name
|
43 |
save_uploaded_image(image, save_image)
|
44 |
convert_text_to_txt(multimodal_text, save_txt)
|
|
|
46 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
47 |
|
48 |
bert_model='vinai/phobert-base-v2'
|
49 |
+
output_dir='Model/MultimodelNER/VLSP2016/best_model'
|
50 |
output_model_file = os.path.join(output_dir, WEIGHTS_NAME)
|
51 |
output_encoder_file = os.path.join(output_dir, "pytorch_encoder.bin")
|
52 |
processor = MNERProcessor_2016()
|
|
|
70 |
trans_matrix[6, 12] = 1
|
71 |
tokenizer = AutoTokenizer.from_pretrained(bert_model, do_lower_case=False)
|
72 |
model_umt, encoder_umt = load_model(output_model_file, output_encoder_file, encoder,num_labels,auxnum_labels)
|
73 |
+
eval_examples = get_test_examples_predict('Model/MultimodelNER/VLSP2016/Filetxt/')
|
74 |
|
75 |
y_pred, a = predict(model_umt, encoder_umt, eval_examples, tokenizer, device,save_image,trans_matrix)
|
76 |
formatted_output = format_predictions(a, y_pred[0])
|