Instructions to use FredZhang7/google-safesearch-mini-tfjs with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TF-Keras
How to use FredZhang7/google-safesearch-mini-tfjs with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy) # See https://github.com/keras-team/tf-keras for more details. from huggingface_hub import from_pretrained_keras model = from_pretrained_keras("FredZhang7/google-safesearch-mini-tfjs") - Notebooks
- Google Colab
- Kaggle
Commit ·
abb0c7a
1
Parent(s): a0de6a5
Upload model
Browse files
Model.py
CHANGED
|
@@ -2,7 +2,6 @@ from transformers import PreTrainedModel
|
|
| 2 |
import torch
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
| 6 |
class InceptionV3ModelForImageClassification(PreTrainedModel):
|
| 7 |
def __init__(self, config):
|
| 8 |
super().__init__(config)
|
|
@@ -10,12 +9,11 @@ class InceptionV3ModelForImageClassification(PreTrainedModel):
|
|
| 10 |
model_path = f"{self.config.model_name}.bin".replace("/","_")
|
| 11 |
|
| 12 |
if self.config.model_name == "google-safesearch-mini":
|
|
|
|
|
|
|
| 13 |
self.model = torch.jit.load(model_path)
|
| 14 |
else:
|
| 15 |
-
|
| 16 |
-
from urllib.request import urlretrieve
|
| 17 |
-
urlretrieve(f"https://huggingface.co/{self.config.model_name}/resolve/main/pytorch_model.bin", model_path)
|
| 18 |
-
self.model = torch.jit.load(model_path) if self.config.use_jit else torch.load(model_path)
|
| 19 |
|
| 20 |
def forward(self, input_ids):
|
| 21 |
return self.model(input_ids), None if self.config.model_name == "inception_v3" else self.model(input_ids)
|
|
|
|
| 2 |
import torch
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
class InceptionV3ModelForImageClassification(PreTrainedModel):
|
| 6 |
def __init__(self, config):
|
| 7 |
super().__init__(config)
|
|
|
|
| 9 |
model_path = f"{self.config.model_name}.bin".replace("/","_")
|
| 10 |
|
| 11 |
if self.config.model_name == "google-safesearch-mini":
|
| 12 |
+
if not os.path.exists(model_path):
|
| 13 |
+
model_path = f"./InceptionV3/{model_path}"
|
| 14 |
self.model = torch.jit.load(model_path)
|
| 15 |
else:
|
| 16 |
+
raise ValueError(f"Model {self.config.model_name} not found.")
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def forward(self, input_ids):
|
| 19 |
return self.model(input_ids), None if self.config.model_name == "inception_v3" else self.model(input_ids)
|