joeyaintjoking commited on
Commit
b1713d3
·
1 Parent(s): 9bf48ec

initial commit

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv
Dockerfile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python image
2
+ FROM python:3.10-slim
3
+
4
+ # Set working directory
5
+ WORKDIR /code
6
+
7
+ # Install system dependencies (optional)
8
+ RUN apt-get update && apt-get install -y git
9
+
10
+ # Install Python dependencies
11
+ COPY requirements.txt .
12
+ RUN pip install --upgrade pip
13
+ RUN pip install -r requirements.txt
14
+
15
+ # Copy model and app
16
+ COPY . .
17
+
18
+ # Expose the default HF Spaces port
19
+ EXPOSE 7860
20
+
21
+ # Run the FastAPI app using Uvicorn
22
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
+ import pandas as pd
4
+ from autogluon.multimodal import MultiModalPredictor
5
+
6
+ app = FastAPI()
7
+
8
+ # Load the model
9
+ predictor = MultiModalPredictor.load("model_ml_dart")
10
+
11
+ # Input schema
12
+ class PredictionInput(BaseModel):
13
+ anchor_age: int
14
+ dbp: int
15
+ heart_rate: int
16
+ sbp: int
17
+ pH: float
18
+ PaCO2: float
19
+ PaO2: float
20
+ HCO3: float
21
+ SaO2: float
22
+ Compliance: float
23
+ Flow_Rate_L_min: float
24
+ Inspired_O2_Fraction: float
25
+ Minute_Volume: float
26
+ Peak_Insp_Pressure: float
27
+ Plateau_Pressure: float
28
+ Resistance_Exp: float
29
+ Resistance_Insp: float
30
+ Respiratory_Rate_Total: float
31
+ Tidal_Volume_observed: float
32
+ Tidal_Volume_set: float
33
+ Total_PEEP_Level: float
34
+ respiratory_diagnoses: str
35
+
36
+ # Column renaming to match training data
37
+ rename_map = {
38
+ "anchor_age": "anchor_age",
39
+ "dbp": "dbp",
40
+ "heart_rate": "heart_rate",
41
+ "sbp": "sbp",
42
+ "pH": "pH",
43
+ "PaCO2": "PaCO2",
44
+ "PaO2": "PaO2",
45
+ "HCO3": "HCO3",
46
+ "SaO2": "SaO2",
47
+ "Compliance": "Compliance",
48
+ "Flow_Rate_L_min": "Flow Rate (L/min)",
49
+ "Inspired_O2_Fraction": "Inspired O2 Fraction",
50
+ "Minute_Volume": "Minute Volume",
51
+ "Peak_Insp_Pressure": "Peak Insp. Pressure",
52
+ "Plateau_Pressure": "Plateau Pressure",
53
+ "Resistance_Exp": "Resistance Exp",
54
+ "Resistance_Insp": "Resistance Insp",
55
+ "Respiratory_Rate_Total": "Respiratory Rate (Total)",
56
+ "Tidal_Volume_observed": "Tidal Volume (observed)",
57
+ "Tidal_Volume_set": "Tidal Volume (set)",
58
+ "Total_PEEP_Level": "Total PEEP Level",
59
+ "respiratory_diagnoses": "respiratory_diagnoses"
60
+ }
61
+
62
+ # Mapping from predicted class index to readable label
63
+ label_map = {
64
+ 0: "APRV",
65
+ 1: "CMV",
66
+ 2: "NIV",
67
+ 3: "SPECIAL",
68
+ 4: "PSV",
69
+ 5: "SIMV",
70
+ 6: "SPONT"
71
+ }
72
+
73
+ @app.post("/predict")
74
+ def predict(input_data: PredictionInput):
75
+ try:
76
+ # Rename input fields to match training data
77
+ input_dict = input_data.dict()
78
+ renamed_input = {rename_map[k]: v for k, v in input_dict.items()}
79
+ df = pd.DataFrame([renamed_input])
80
+
81
+ # Run prediction
82
+ raw_prediction = predictor.predict(df)[0]
83
+
84
+ # Convert numeric label to string label
85
+ ventilation_mode = label_map.get(int(raw_prediction), "Unknown")
86
+
87
+ return {"ventilation_mode": ventilation_mode}
88
+
89
+ except Exception as e:
90
+ raise HTTPException(status_code=500, detail=f"Prediction failed: {str(e)}")
model_ml_dart/assets.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"learner_class": "BaseLearner", "column_types": {"dbp": "numerical", "heart_rate": "numerical", "sbp": "numerical", "pH": "numerical", "PaCO2": "numerical", "PaO2": "numerical", "HCO3": "numerical", "SaO2": "numerical", "Compliance": "numerical", "Flow Rate (L/min)": "numerical", "Inspired O2 Fraction": "numerical", "Minute Volume": "numerical", "Peak Insp. Pressure": "numerical", "Plateau Pressure": "numerical", "Resistance Exp": "numerical", "Resistance Insp": "numerical", "Respiratory Rate (Total)": "numerical", "Tidal Volume (observed)": "numerical", "Tidal Volume (set)": "numerical", "Total PEEP Level": "numerical", "respiratory_diagnoses": "text", "vent_mode_group_enc": "categorical"}, "label_column": "vent_mode_group_enc", "problem_type": "multiclass", "presets": null, "eval_metric_name": "accuracy", "validation_metric_name": "accuracy", "minmax_mode": "max", "output_shape": 7, "save_path": "/kaggle/working/AutogluonModels/ag-20250803_114221", "pretrained": true, "pretrained_path": null, "fit_called": true, "best_score": null, "total_train_time": null, "version": "1.4.0"}
model_ml_dart/config.yaml ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ model:
2
+ names:
3
+ - ft_transformer
4
+ - fusion_mlp
5
+ - hf_text
6
+ hf_text:
7
+ checkpoint_name: local://hf_text
8
+ gradient_checkpointing: false
9
+ pooling_mode: cls
10
+ data_types:
11
+ - text
12
+ tokenizer_name: hf_auto
13
+ use_fast: true
14
+ max_text_len: 512
15
+ insert_sep: true
16
+ low_cpu_mem_usage: false
17
+ text_segment_num: 2
18
+ stochastic_chunk: false
19
+ text_aug_detect_length: 10
20
+ text_trivial_aug_maxscale: 0.1
21
+ text_train_augment_types: null
22
+ fusion_mlp:
23
+ aux_loss_weight: null
24
+ adapt_in_features: max
25
+ hidden_sizes:
26
+ - 128
27
+ activation: leaky_relu
28
+ dropout: 0.1
29
+ normalization: layer_norm
30
+ data_types: null
31
+ ft_transformer:
32
+ data_types:
33
+ - numerical
34
+ embedding_arch:
35
+ - linear
36
+ token_dim: 192
37
+ hidden_size: 192
38
+ num_blocks: 3
39
+ attention_num_heads: 8
40
+ attention_dropout: 0.2
41
+ residual_dropout: 0.0
42
+ ffn_dropout: 0.1
43
+ ffn_hidden_size: 192
44
+ ffn_activation: geglu
45
+ head_activation: relu
46
+ normalization: layer_norm
47
+ merge: concat
48
+ requires_all_dtypes: false
49
+ additive_attention: false
50
+ share_qv_weights: false
51
+ pooling_mode: cls
52
+ checkpoint_name: null
53
+ data:
54
+ image:
55
+ missing_value_strategy: zero
56
+ text:
57
+ normalize_text: false
58
+ categorical:
59
+ minimum_cat_count: 100
60
+ maximum_num_cat: 20
61
+ convert_to_text: false
62
+ convert_to_text_template: latex
63
+ numerical:
64
+ convert_to_text: false
65
+ scaler_with_mean: true
66
+ scaler_with_std: true
67
+ document:
68
+ missing_value_strategy: zero
69
+ label:
70
+ numerical_preprocessing: standardscaler
71
+ pos_label: null
72
+ column_features_pooling_mode: concat
73
+ mixup:
74
+ turn_on: false
75
+ mixup_alpha: 0.8
76
+ cutmix_alpha: 1.0
77
+ cutmix_minmax: null
78
+ prob: 1.0
79
+ switch_prob: 0.5
80
+ mode: batch
81
+ turn_off_epoch: 5
82
+ label_smoothing: 0.1
83
+ modality_dropout: 0
84
+ templates:
85
+ turn_on: false
86
+ num_templates: 30
87
+ template_length: 2048
88
+ preset_templates:
89
+ - super_glue
90
+ - rte
91
+ custom_templates: null
92
+ optim:
93
+ optim_type: adamw
94
+ lr: 0.0001
95
+ weight_decay: 0.001
96
+ lr_choice: layerwise_decay
97
+ lr_decay: 0.9
98
+ lr_schedule: cosine_decay
99
+ max_epochs: 20
100
+ max_steps: -1
101
+ warmup_steps: 0.1
102
+ end_lr: 0
103
+ lr_mult: 1
104
+ patience: 10
105
+ val_check_interval: 0.5
106
+ check_val_every_n_epoch: 1
107
+ skip_final_val: false
108
+ gradient_clip_val: 1
109
+ gradient_clip_algorithm: norm
110
+ track_grad_norm: -1
111
+ log_every_n_steps: 10
112
+ label_smoothing: 0
113
+ top_k: 3
114
+ top_k_average_method: greedy_soup
115
+ peft: null
116
+ lora:
117
+ module_filter: null
118
+ filter:
119
+ - query
120
+ - value
121
+ - ^q$
122
+ - ^v$
123
+ - ^k$
124
+ - ^o$
125
+ r: 8
126
+ alpha: 8
127
+ conv_lora_expert_num: 8
128
+ loss_func: auto
129
+ focal_loss:
130
+ alpha: null
131
+ gamma: 2.0
132
+ reduction: mean
133
+ mask2former_loss:
134
+ loss_cross_entropy_weight: 10.0
135
+ loss_mask_weight: 5.0
136
+ loss_dice_weight: 5.0
137
+ extra_trainable_params: []
138
+ cross_modal_align: null
139
+ cross_modal_align_weight: 0
140
+ automatic_optimization: true
141
+ lemda:
142
+ turn_on: false
143
+ arch_type: mlp_vae
144
+ z_dim: 8
145
+ num_layers: 6
146
+ kld_weight: 0.1
147
+ mse_weight: 0.1
148
+ adv_weight: 0.0001
149
+ consist_weight: 0.01
150
+ consist_threshold: 0.5
151
+ lr: 0.0001
152
+ optim_type: adamw
153
+ weight_decay: 1.0e-05
154
+ env:
155
+ num_gpus: 2
156
+ num_nodes: 1
157
+ batch_size: 128
158
+ per_gpu_batch_size: 8
159
+ inference_batch_size_ratio: 4
160
+ precision: 16-mixed
161
+ num_workers: 2
162
+ num_workers_inference: 2
163
+ accelerator: auto
164
+ fast_dev_run: false
165
+ deterministic: false
166
+ auto_select_gpus: true
167
+ strategy: ddp_fork_find_unused_parameters_true
168
+ deepspeed_allgather_size: 1000000000.0
169
+ deepspeed_allreduce_size: 1000000000.0
170
+ compile:
171
+ turn_on: false
172
+ mode: default
173
+ dynamic: true
174
+ backend: inductor
model_ml_dart/data_processors.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b70e3e39d4220b666ac74a39cada87914f1d48bb366aea9f1855c3e9757e9fa7
3
+ size 17353
model_ml_dart/df_preprocessor.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a130ad40ba45c32c89ec0e9b5b1d61b8b9755141091e39091b569a3ef034f345
3
+ size 26152
model_ml_dart/eval_metric.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b0024ce25367aac2c6595f96f9b18415e8483aa9fb4771dff28ea934a6ce1bca
3
+ size 220
model_ml_dart/events.out.tfevents.1754221349.40c7a73c014d.261.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f8bebd84c9e172b3f3648f1542ab55f5804af249af25971ee1c76af2d1e21fba
3
+ size 10332957
model_ml_dart/hf_text/config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "google/electra-base-discriminator",
3
+ "architectures": [
4
+ "ElectraForPreTraining"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "embedding_size": 768,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "electra",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "summary_activation": "gelu",
22
+ "summary_last_dropout": 0.1,
23
+ "summary_type": "first",
24
+ "summary_use_proj": true,
25
+ "transformers_version": "4.49.0",
26
+ "type_vocab_size": 2,
27
+ "use_cache": true,
28
+ "vocab_size": 30522
29
+ }
model_ml_dart/hf_text/special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
model_ml_dart/hf_text/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
model_ml_dart/hf_text/tokenizer_config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": true,
47
+ "extra_special_tokens": {},
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 512,
50
+ "pad_token": "[PAD]",
51
+ "sep_token": "[SEP]",
52
+ "strip_accents": null,
53
+ "tokenize_chinese_chars": true,
54
+ "tokenizer_class": "ElectraTokenizer",
55
+ "unk_token": "[UNK]"
56
+ }
model_ml_dart/hf_text/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
model_ml_dart/hparams.yaml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ optim_type: adamw
2
+ lr_choice: layerwise_decay
3
+ lr_schedule: cosine_decay
4
+ lr: 0.0001
5
+ lr_decay: 0.9
6
+ end_lr: 0
7
+ lr_mult: 1
8
+ weight_decay: 0.001
9
+ warmup_steps: 0.1
10
+ validation_metric_name: accuracy
11
+ peft: null
12
+ mixup_off_epoch: 5
13
+ skip_final_val: false
14
+ track_grad_norm: -1
15
+ cross_modal_align: null
16
+ cross_modal_align_weight: 0
17
+ automatic_optimization: true
18
+ accumulate_grad_batches: 8
19
+ gradient_clip_val: 1
20
+ gradient_clip_algorithm: norm
21
+ use_aug_optim: false
22
+ aug_lr: 0.0001
23
+ aug_weight_decay: 1.0e-05
24
+ aug_optim_type: adamw
model_ml_dart/model.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a12e8b83bbaaf5f217e9abacc3ceec69dfef901a5da5f553c2f0ff9559e1520
3
+ size 442724170
requirement.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ pydantic
4
+ pandas
5
+ autogluon.multimodal