Linhz commited on
Commit
ce95a0d
1 Parent(s): 3cfcf7e

Update Model/MultimodelNER/VLSP2021/MNER_2021.py

Browse files
Model/MultimodelNER/VLSP2021/MNER_2021.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('/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,8 +37,8 @@ def show_mner_2021():
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/VLSP2021/Image'
41
- save_txt = '/Model/MultimodelNER/VLSP2021/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,7 +46,7 @@ def show_mner_2021():
46
  st.image(image, caption="Uploaded Image", use_column_width=True)
47
 
48
  bert_model = 'vinai/phobert-base-v2'
49
- output_dir = '/Model/MultimodelNER/VLSP2021/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_2021()
@@ -72,7 +72,7 @@ def show_mner_2021():
72
  model_umt, encoder_umt = load_model(output_model_file, output_encoder_file, encoder, num_labels,
73
  auxnum_labels)
74
  eval_examples = get_test_examples_predict(
75
- '/Model/MultimodelNER/VLSP2021/Filetxt/')
76
 
77
  y_pred, a = predict(model_umt, encoder_umt, eval_examples, tokenizer, device, save_image, trans_matrix)
78
  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/VLSP2021/Image'
41
+ save_txt = 'Model/MultimodelNER/VLSP2021/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/VLSP2021/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_2021()
 
72
  model_umt, encoder_umt = load_model(output_model_file, output_encoder_file, encoder, num_labels,
73
  auxnum_labels)
74
  eval_examples = get_test_examples_predict(
75
+ 'Model/MultimodelNER/VLSP2021/Filetxt/')
76
 
77
  y_pred, a = predict(model_umt, encoder_umt, eval_examples, tokenizer, device, save_image, trans_matrix)
78
  formatted_output = format_predictions(a, y_pred[0])