Ali commited on
Commit
347a08e
·
1 Parent(s): 6e78300

Add YOLOv8n weights

Browse files
SA_Model/config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation": "gelu",
3
+ "architectures": [
4
+ "DistilBertForSequenceClassification"
5
+ ],
6
+ "attention_dropout": 0.1,
7
+ "dim": 768,
8
+ "dropout": 0.1,
9
+ "dtype": "float32",
10
+ "finetuning_task": "sst-2",
11
+ "hidden_dim": 3072,
12
+ "id2label": {
13
+ "0": "NEGATIVE",
14
+ "1": "POSITIVE"
15
+ },
16
+ "initializer_range": 0.02,
17
+ "label2id": {
18
+ "NEGATIVE": 0,
19
+ "POSITIVE": 1
20
+ },
21
+ "max_position_embeddings": 512,
22
+ "model_type": "distilbert",
23
+ "n_heads": 12,
24
+ "n_layers": 6,
25
+ "output_past": true,
26
+ "pad_token_id": 0,
27
+ "qa_dropout": 0.1,
28
+ "seq_classif_dropout": 0.2,
29
+ "sinusoidal_pos_embds": false,
30
+ "tie_weights_": true,
31
+ "transformers_version": "4.56.1",
32
+ "vocab_size": 30522
33
+ }
SA_Model/handler.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # handler.py
2
+ import time
3
+ from typing import Any, Dict, List, Union
4
+ from transformers import pipeline
5
+
6
+ class EndpointHandler:
7
+ def __init__(self, path: str = ""):
8
+ # Load a standard text-classification pipeline from local repo files
9
+ self.pipe = pipeline("text-classification", model=path)
10
+
11
+ def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
12
+ # Accept {"inputs": "..."} or {"inputs": ["...", "..."]}
13
+ inputs: Union[str, List[str]] = data.get("inputs", data)
14
+
15
+ t0 = time.perf_counter()
16
+ preds = self.pipe(inputs, truncation=True)
17
+ elapsed = time.perf_counter() - t0
18
+
19
+ # Normalize to list
20
+ preds_list = preds if isinstance(preds, list) else [preds]
21
+ labels = [p["label"] for p in preds_list]
22
+ scores = [float(p["score"]) for p in preds_list]
23
+
24
+ return {
25
+ "labels": labels,
26
+ "scores": scores,
27
+ "processing_time_sec": elapsed,
28
+ }
SA_Model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61afb985df6fbe77fd84138129481f0a4444c02893782984e330f874f43cee4b
3
+ size 267832560
SA_Model/prepare_model.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # prepare_model.py
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+
4
+ MODEL = "distilbert-base-uncased-finetuned-sst-2-english"
5
+
6
+ m = AutoModelForSequenceClassification.from_pretrained(MODEL)
7
+ t = AutoTokenizer.from_pretrained(MODEL)
8
+
9
+ m.save_pretrained(".") # saves config.json + weights (bin/safetensors)
10
+ t.save_pretrained(".") # saves tokenizer files
11
+ print("Saved model + tokenizer to repo root")
SA_Model/readme.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - sentiment-analysis
4
+ - text-classification
5
+ pipeline_tag: text-classification
6
+ language:
7
+ - en
8
+ license: apache-2.0
9
+ library_name: transformers
10
+ model_name: distilbert-base-uncased-finetuned-sst-2-english
11
+ ---
12
+
13
+ # Ericsson Day Demo Sentiment Model
14
+
15
+ This model is based on **DistilBERT fine-tuned on SST-2** for sentiment analysis.
16
+ It has been wrapped with a custom `model.py` that also reports the internal processing time.
17
+
18
+ ## Model description
19
+ - **Task**: Sentiment classification (positive/negative)
20
+ - **Base model**: `distilbert-base-uncased-finetuned-sst-2-english`
21
+ - **Wrapper**: Custom `model.py` that returns `"processing_time_sec"`
22
+
23
+ ## Example usage
24
+
25
+ ```python
26
+ from transformers import pipeline
27
+ classifier = pipeline("sentiment-analysis", model="ED-Demo/Ericsson_day_demo_model")
28
+ print(classifier("I love Hugging Face!"))
SA_Model/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers
SA_Model/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
+ }
SA_Model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
SA_Model/tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "DistilBertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
SA_Model/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
Yolo_Model/.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ Yolo_Model/yolov8n.pt filter=lfs diff=lfs merge=lfs -text
tests/test_SA_RTT.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import requests
4
+ import statistics
5
+
6
+ # Your endpoint + token
7
+ ENDPOINT_URL = "https://igyvdwvwkcoglpbx.eu-west-1.aws.endpoints.huggingface.cloud"
8
+ HF_TOKEN = os.getenv("HF_TOKEN") # put your token in environment: export HF_TOKEN=hf_xxx
9
+
10
+ headers = {
11
+ "Authorization": f"Bearer {HF_TOKEN}",
12
+ "Content-Type": "application/json"
13
+ }
14
+
15
+ payload = {"inputs": "This is fantastic!"}
16
+
17
+ latencies = []
18
+
19
+ # Warmup (optional: remove if you want cold start time)
20
+ requests.post(ENDPOINT_URL, headers=headers, json=payload)
21
+
22
+ for i in range(50):
23
+ t0 = time.perf_counter()
24
+ r = requests.post(ENDPOINT_URL, headers=headers, json=payload)
25
+ dt = time.perf_counter() - t0
26
+ latencies.append(dt)
27
+ print(f"Run {i+1}: RTT={dt:.3f}s, Response={r.json()}")
28
+
29
+ print("\n📊 RTT stats (10 runs)")
30
+ print(f" Min : {min(latencies):.3f}s")
31
+ print(f" Avg : {statistics.mean(latencies):.3f}s")
32
+ print(f" Median: {statistics.median(latencies):.3f}s")
33
+ print(f" Max : {max(latencies):.3f}s")
tests/test_roundtrip.py DELETED
@@ -1,24 +0,0 @@
1
- import time, statistics, os
2
- from huggingface_hub import InferenceClient
3
-
4
- ENDPOINT_URL = "https://<your-endpoint>.endpoints.huggingface.cloud"
5
- HF_TOKEN = os.getenv("HF_TOKEN")
6
-
7
- client = InferenceClient(endpoint_url=ENDPOINT_URL, token=HF_TOKEN)
8
-
9
- def measure_rtt(n=5):
10
- print("⚡ Warming up...")
11
- client.post(json={"inputs": "Warmup test"})
12
-
13
- latencies = []
14
- for i in range(n):
15
- t0 = time.perf_counter()
16
- out = client.post(json={"inputs": "This is fantastic!"})
17
- dt = time.perf_counter() - t0
18
- latencies.append(dt)
19
- print(f"Run {i+1}: RTT={dt:.3f}s | Output={out}")
20
-
21
- print(f"\n✅ RTT stats: min={min(latencies):.3f}s, median={statistics.median(latencies):.3f}s, max={max(latencies):.3f}s")
22
-
23
- if __name__ == "__main__":
24
- measure_rtt()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test_yolo.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ from ultralytics import YOLO
3
+
4
+ # Load model
5
+ model = YOLO("yolov8n.pt") # or path to your custom weights
6
+
7
+ # Force index 0 (usually the MacBook’s built-in camera) using AVFoundation
8
+ cap = cv2.VideoCapture(2, cv2.CAP_AVFOUNDATION)
9
+
10
+ if not cap.isOpened():
11
+ print("Cannot open camera 0, try index 1")
12
+ cap = cv2.VideoCapture(1, cv2.CAP_AVFOUNDATION)
13
+ if not cap.isOpened():
14
+ raise IOError("Cannot open any webcam")
15
+
16
+ while True:
17
+ ret, frame = cap.read()
18
+ if not ret:
19
+ break
20
+
21
+ # Run YOLO inference
22
+ results = model(frame)
23
+
24
+ # Draw results on frame
25
+ annotated_frame = results[0].plot()
26
+
27
+ # Get inference time (ms)
28
+ inf_time = results[0].speed["inference"]
29
+ text = f"Inference: {inf_time:.1f} ms"
30
+
31
+ # Overlay text on the frame
32
+ cv2.putText(
33
+ annotated_frame,
34
+ text,
35
+ (20, 40), # position (x, y)
36
+ cv2.FONT_HERSHEY_SIMPLEX,
37
+ 1, # font scale
38
+ (0, 255, 0), # green color
39
+ 2, # thickness
40
+ cv2.LINE_AA
41
+ )
42
+
43
+ # Show
44
+ cv2.imshow("YOLOv8 Webcam", annotated_frame)
45
+
46
+ # Press 'q' to quit
47
+ key = cv2.waitKey(10) & 0xFF
48
+ if key == ord("q"):
49
+ break
50
+
51
+ cap.release()
52
+ cv2.destroyAllWindows()