Upload folder using huggingface_hub
Browse files- README.md +53 -0
- entities.json +149 -0
- events.json +117 -0
- model.py +21 -0
- pytorch_model.pth +3 -0
README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- framenet
|
| 6 |
+
- multimodal
|
| 7 |
+
- neuro-symbolic
|
| 8 |
+
library_name: pytorch
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# 🧠 ReINVenTA: Event Classifier (Fusion WiSE)
|
| 12 |
+
|
| 13 |
+
Este é o modelo **SOTA** do Estágio 3. Classifica **Eventos Semânticos** combinando visão (CLIP) e lógica (YOLO).
|
| 14 |
+
|
| 15 |
+
## 📊 Performance
|
| 16 |
+
- **Recall@5:** 68.1%
|
| 17 |
+
- **Arquitetura:** Fusion WiSE (Late Fusion MLP)
|
| 18 |
+
|
| 19 |
+
## 💻 Como usar (Python API)
|
| 20 |
+
|
| 21 |
+
### 1. Instalação
|
| 22 |
+
```bash
|
| 23 |
+
pip install huggingface_hub torch
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
### 2. Código de Inferência
|
| 27 |
+
```python
|
| 28 |
+
import torch
|
| 29 |
+
import json
|
| 30 |
+
from huggingface_hub import hf_hub_download
|
| 31 |
+
import sys
|
| 32 |
+
import os
|
| 33 |
+
|
| 34 |
+
# 1. Baixar arquivos
|
| 35 |
+
repo_id = "FrameNetBrasil/reinventa-event-classifier-fusion-wise"
|
| 36 |
+
model_path = hf_hub_download(repo_id=repo_id, filename="pytorch_model.pth")
|
| 37 |
+
code_path = hf_hub_download(repo_id=repo_id, filename="model.py")
|
| 38 |
+
ent_path = hf_hub_download(repo_id=repo_id, filename="entities.json")
|
| 39 |
+
evt_path = hf_hub_download(repo_id=repo_id, filename="events.json")
|
| 40 |
+
|
| 41 |
+
# 2. Importar Classe Customizada
|
| 42 |
+
sys.path.append(os.path.dirname(code_path))
|
| 43 |
+
from model import FusionWiSE
|
| 44 |
+
|
| 45 |
+
# 3. Carregar
|
| 46 |
+
with open(ent_path) as f: ents = json.load(f)
|
| 47 |
+
with open(evt_path) as f: evts = json.load(f)
|
| 48 |
+
|
| 49 |
+
model = FusionWiSE(clip_dim=512, entity_dim=len(ents), num_classes=len(evts))
|
| 50 |
+
model.load_state_dict(torch.load(model_path, map_location='cpu'))
|
| 51 |
+
model.eval()
|
| 52 |
+
print('✅ Modelo carregado!')
|
| 53 |
+
```
|
entities.json
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"Accoutrements.Accoutrement",
|
| 3 |
+
"Accoutrements.Descriptor",
|
| 4 |
+
"Accoutrements.Wearer",
|
| 5 |
+
"Activity.Activity",
|
| 6 |
+
"Aggregate.Aggregate",
|
| 7 |
+
"Aggregate.Individuals",
|
| 8 |
+
"Animals.Animal",
|
| 9 |
+
"Animals.Characteristic",
|
| 10 |
+
"Appliances.Appliance",
|
| 11 |
+
"Architectural_part.Part",
|
| 12 |
+
"Architectural_part.Whole",
|
| 13 |
+
"Artifact.Artifact",
|
| 14 |
+
"Artifact.Material",
|
| 15 |
+
"Artifact.Name",
|
| 16 |
+
"Artifact.Place",
|
| 17 |
+
"Artifact.Use",
|
| 18 |
+
"Artifact_subpart.Artifact",
|
| 19 |
+
"Assemble.Individuals",
|
| 20 |
+
"Athletes.Athlete",
|
| 21 |
+
"Athletes_by_position.Position",
|
| 22 |
+
"Athletes_by_sport.Athlete",
|
| 23 |
+
"Basis_for_attribute.Figure",
|
| 24 |
+
"Biological_area.Locale",
|
| 25 |
+
"Body_decoration.Decoration",
|
| 26 |
+
"Body_parts.Body_part",
|
| 27 |
+
"Body_parts.Possessor",
|
| 28 |
+
"Building_subparts.Building_part",
|
| 29 |
+
"Building_subparts.Place",
|
| 30 |
+
"Building_subparts.Whole",
|
| 31 |
+
"Buildings.Building",
|
| 32 |
+
"Businesses.Business",
|
| 33 |
+
"Businesses.Place",
|
| 34 |
+
"Calendric_unit.Relative_time",
|
| 35 |
+
"Calendric_unit.Unit",
|
| 36 |
+
"Cardinal_numbers.Number",
|
| 37 |
+
"Clothing.Descriptor",
|
| 38 |
+
"Clothing.Garment",
|
| 39 |
+
"Clothing.Style",
|
| 40 |
+
"Clothing.Wearer",
|
| 41 |
+
"Clothing_parts.Clothing",
|
| 42 |
+
"Clothing_parts.Subpart",
|
| 43 |
+
"Clothing_parts.Wearer",
|
| 44 |
+
"Color.Color",
|
| 45 |
+
"Communication_means.Means",
|
| 46 |
+
"Connecting_architecture.Part",
|
| 47 |
+
"Connectors.Connector",
|
| 48 |
+
"Containers.Container",
|
| 49 |
+
"Create_representation.Representation",
|
| 50 |
+
"Dining.Establishment",
|
| 51 |
+
"Entity.Constituent_parts",
|
| 52 |
+
"Entity.Context_of_acquaintance",
|
| 53 |
+
"Entity.Descriptor",
|
| 54 |
+
"Entity.Discipline",
|
| 55 |
+
"Entity.Entity",
|
| 56 |
+
"Entity.Ethnicity",
|
| 57 |
+
"Entity.Part",
|
| 58 |
+
"Entity.Type",
|
| 59 |
+
"Entity.Use",
|
| 60 |
+
"Event.Event",
|
| 61 |
+
"Eventive.Place",
|
| 62 |
+
"Eventive.Theme",
|
| 63 |
+
"Facial_expression.Expression",
|
| 64 |
+
"Fire_burning.Fire",
|
| 65 |
+
"Food.Food",
|
| 66 |
+
"Furniture.Piece_of_furniture",
|
| 67 |
+
"Gizmo.Gizmo",
|
| 68 |
+
"Hair_configuration.Configuration",
|
| 69 |
+
"Hair_configuration.Hair",
|
| 70 |
+
"Information_display.Display",
|
| 71 |
+
"Ingredients.Material",
|
| 72 |
+
"Intoxicants.Intoxicant",
|
| 73 |
+
"Kinship.Alter",
|
| 74 |
+
"Kinship.Ego",
|
| 75 |
+
"Limitation.Entity",
|
| 76 |
+
"Locale.Descriptor",
|
| 77 |
+
"Locale.Locale",
|
| 78 |
+
"Locale.Name",
|
| 79 |
+
"Locale.Relative_location",
|
| 80 |
+
"Locale_by_event.Locale",
|
| 81 |
+
"Locale_by_use.Locale",
|
| 82 |
+
"Locative_relation.Ground",
|
| 83 |
+
"Machinery.Machinery",
|
| 84 |
+
"Means_of_transportation.Means_of_transportation",
|
| 85 |
+
"Moves.Move",
|
| 86 |
+
"Musical_instruments.Musical_instrument",
|
| 87 |
+
"Natural_features.Constituent_parts",
|
| 88 |
+
"Natural_features.Locale",
|
| 89 |
+
"Part_piece.Piece",
|
| 90 |
+
"Part_whole.Part",
|
| 91 |
+
"People.Age",
|
| 92 |
+
"People.Descriptor",
|
| 93 |
+
"People.Persistent_characteristic",
|
| 94 |
+
"People.Person",
|
| 95 |
+
"People_by_age.Age",
|
| 96 |
+
"People_by_age.Persistent_characteristic",
|
| 97 |
+
"People_by_age.Person",
|
| 98 |
+
"People_by_ethnicity.Person",
|
| 99 |
+
"People_by_leisure_activity.Leisure_activity",
|
| 100 |
+
"People_by_leisure_activity.Person",
|
| 101 |
+
"People_by_origin.Person",
|
| 102 |
+
"People_by_social_framing.Person",
|
| 103 |
+
"People_by_transitory_activity.Person",
|
| 104 |
+
"People_by_vocation.Context_of_acquaintance",
|
| 105 |
+
"People_by_vocation.Person",
|
| 106 |
+
"People_by_vocation.Type",
|
| 107 |
+
"Performers_and_roles.Place",
|
| 108 |
+
"Performing_arts.Performance",
|
| 109 |
+
"Performing_arts.Performer",
|
| 110 |
+
"Personal_relationship.Partner_1",
|
| 111 |
+
"Personal_relationship.Partner_2",
|
| 112 |
+
"Personal_relationship.Partners",
|
| 113 |
+
"Physical_artworks.Artifact",
|
| 114 |
+
"Plants.Plant",
|
| 115 |
+
"Political_locales.Locale",
|
| 116 |
+
"Precipitation.Precipitation",
|
| 117 |
+
"Representing.Entity",
|
| 118 |
+
"Roadways.Roadway",
|
| 119 |
+
"Setting_fire.Flame",
|
| 120 |
+
"Shaped_part.Part",
|
| 121 |
+
"Shapes.Shape",
|
| 122 |
+
"Social_event.Social_event",
|
| 123 |
+
"Sports.Sport",
|
| 124 |
+
"Sports_equipment.Equipment",
|
| 125 |
+
"Sports_event.Event",
|
| 126 |
+
"Sports_event.Sport",
|
| 127 |
+
"Sports_venues.Place",
|
| 128 |
+
"Sports_venues.Venue",
|
| 129 |
+
"Sports_venues_subparts.Part",
|
| 130 |
+
"Sports_venues_subparts.Venue",
|
| 131 |
+
"Substance.Substance",
|
| 132 |
+
"Substance_by_phase.Substance",
|
| 133 |
+
"Text.Medium",
|
| 134 |
+
"Text.Text",
|
| 135 |
+
"Toys.Toy",
|
| 136 |
+
"Transportation.Transit",
|
| 137 |
+
"Urban_furniture.Furniture",
|
| 138 |
+
"Utensils.Utensil",
|
| 139 |
+
"Vehicle.Vehicle",
|
| 140 |
+
"Vehicle_subpart.Part",
|
| 141 |
+
"Weapon.Weapon",
|
| 142 |
+
"Weather.Place",
|
| 143 |
+
"Weather.Time",
|
| 144 |
+
"frm_ferramenta.fe_Ferramenta",
|
| 145 |
+
"frm_patterns.fe_Patterns_Shape",
|
| 146 |
+
"frm_people_by_transit_mode.frm_people_by_transit_mode_fe_person_2618_tpl_people",
|
| 147 |
+
"frm_pessoas_por_g\u00eanero.fe_pessoas_por_g\u00eanero_g\u00eanero",
|
| 148 |
+
"frm_pessoas_por_g\u00eanero.fe_pessoas_por_g\u00eanero_pessoas"
|
| 149 |
+
]
|
events.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"Abounding_with",
|
| 3 |
+
"Activity",
|
| 4 |
+
"Activity_ongoing",
|
| 5 |
+
"Activity_prepare",
|
| 6 |
+
"Adjacency",
|
| 7 |
+
"Agriculture",
|
| 8 |
+
"Arranging",
|
| 9 |
+
"Arriving",
|
| 10 |
+
"Artifact",
|
| 11 |
+
"Assistance",
|
| 12 |
+
"Athletes",
|
| 13 |
+
"Attaching",
|
| 14 |
+
"Attempt",
|
| 15 |
+
"Attributes",
|
| 16 |
+
"Being_located",
|
| 17 |
+
"Body_movement",
|
| 18 |
+
"Bringing",
|
| 19 |
+
"Building",
|
| 20 |
+
"Cause_fluidic_motion",
|
| 21 |
+
"Cause_harm",
|
| 22 |
+
"Cause_impact",
|
| 23 |
+
"Cause_motion",
|
| 24 |
+
"Cause_to_make_noise",
|
| 25 |
+
"Cause_to_perceive",
|
| 26 |
+
"Change_posture",
|
| 27 |
+
"Chatting",
|
| 28 |
+
"Closure",
|
| 29 |
+
"Clothing",
|
| 30 |
+
"Come_together",
|
| 31 |
+
"Commerce_buy",
|
| 32 |
+
"Commerce_sell",
|
| 33 |
+
"Communication",
|
| 34 |
+
"Competition",
|
| 35 |
+
"Cooking_creation",
|
| 36 |
+
"Cotheme",
|
| 37 |
+
"Create_physical_artwork",
|
| 38 |
+
"Create_representation",
|
| 39 |
+
"Crowd_reactions",
|
| 40 |
+
"Cutting",
|
| 41 |
+
"Departing",
|
| 42 |
+
"Distributed_position",
|
| 43 |
+
"Do_phisical_activity",
|
| 44 |
+
"Emotions",
|
| 45 |
+
"Emptying",
|
| 46 |
+
"Entity",
|
| 47 |
+
"Event",
|
| 48 |
+
"Eventive",
|
| 49 |
+
"Exercising",
|
| 50 |
+
"Experiencer_focused_emotion",
|
| 51 |
+
"Facial_expression",
|
| 52 |
+
"Filling",
|
| 53 |
+
"Fluidic_motion",
|
| 54 |
+
"Gesture",
|
| 55 |
+
"Give_impression",
|
| 56 |
+
"Giving",
|
| 57 |
+
"Go_dancing",
|
| 58 |
+
"Gradable_attributes",
|
| 59 |
+
"Grooming",
|
| 60 |
+
"Hostile_encounter",
|
| 61 |
+
"Hunting",
|
| 62 |
+
"Individual_moves",
|
| 63 |
+
"Ingest_substance",
|
| 64 |
+
"Ingestion",
|
| 65 |
+
"Inspecting",
|
| 66 |
+
"Intentional_traversing",
|
| 67 |
+
"Intentionally_act",
|
| 68 |
+
"Intentionally_affect",
|
| 69 |
+
"Intentionally_create",
|
| 70 |
+
"Interactive_moves",
|
| 71 |
+
"Locative_relation",
|
| 72 |
+
"Make_noise",
|
| 73 |
+
"Making_faces",
|
| 74 |
+
"Manipulation",
|
| 75 |
+
"Manufacturing",
|
| 76 |
+
"Motion",
|
| 77 |
+
"Motion_directional",
|
| 78 |
+
"Moves",
|
| 79 |
+
"Moving_in_place",
|
| 80 |
+
"Musical_instruments",
|
| 81 |
+
"Operate_vehicle",
|
| 82 |
+
"Operating_a_system",
|
| 83 |
+
"Participation",
|
| 84 |
+
"People",
|
| 85 |
+
"Perception_active",
|
| 86 |
+
"Performing_arts",
|
| 87 |
+
"Placing",
|
| 88 |
+
"Political_actions",
|
| 89 |
+
"Posture",
|
| 90 |
+
"Practice",
|
| 91 |
+
"Reading_activity",
|
| 92 |
+
"Reading_perception",
|
| 93 |
+
"Reciprocality",
|
| 94 |
+
"Removing",
|
| 95 |
+
"Ride_vehicle",
|
| 96 |
+
"Scenario",
|
| 97 |
+
"Scrutiny",
|
| 98 |
+
"Self_motion",
|
| 99 |
+
"Sleep",
|
| 100 |
+
"Social_event",
|
| 101 |
+
"Speak_on_topic",
|
| 102 |
+
"Sports_event",
|
| 103 |
+
"State_continue",
|
| 104 |
+
"Statement",
|
| 105 |
+
"Subjective_experience",
|
| 106 |
+
"Surrounding",
|
| 107 |
+
"Taking",
|
| 108 |
+
"Telling",
|
| 109 |
+
"Text_creation",
|
| 110 |
+
"Tourist_activities",
|
| 111 |
+
"Transitive_action",
|
| 112 |
+
"Traversing",
|
| 113 |
+
"Using",
|
| 114 |
+
"Waiting",
|
| 115 |
+
"Wearing",
|
| 116 |
+
"Work"
|
| 117 |
+
]
|
model.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import torch
|
| 3 |
+
import torch.nn as nn
|
| 4 |
+
|
| 5 |
+
class FusionWiSE(nn.Module):
|
| 6 |
+
def __init__(self, clip_dim=512, entity_dim=147, num_classes=115, hidden_dim=512, dropout=0.5):
|
| 7 |
+
super(FusionWiSE, self).__init__()
|
| 8 |
+
self.encoder = nn.Sequential(
|
| 9 |
+
nn.Linear(clip_dim + entity_dim, hidden_dim),
|
| 10 |
+
nn.BatchNorm1d(hidden_dim),
|
| 11 |
+
nn.ReLU(),
|
| 12 |
+
nn.Dropout(dropout),
|
| 13 |
+
nn.Linear(hidden_dim, hidden_dim)
|
| 14 |
+
)
|
| 15 |
+
self.classifier = nn.Linear(hidden_dim, num_classes)
|
| 16 |
+
|
| 17 |
+
def forward(self, clip_emb, entity_onehot):
|
| 18 |
+
x = torch.cat([clip_emb, entity_onehot], dim=1)
|
| 19 |
+
feats = self.encoder(x)
|
| 20 |
+
feats = feats / feats.norm(p=2, dim=-1, keepdim=True)
|
| 21 |
+
return self.classifier(feats)
|
pytorch_model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e33fafe67d44ddaeb7813fde45784c2c635a2c300994df2c3aa51569399f11c6
|
| 3 |
+
size 2650797
|