Pujan-Dev commited on
Commit
0fc632b
·
1 Parent(s): 847f771

fixed tthe error

Browse files
features/image_classifier/model_loader.py CHANGED
@@ -1,29 +1,21 @@
1
  import os
2
  import shutil
3
  import logging
4
- import tensorflow as tf
5
- from tensorflow.keras.layers import Layer
6
  from huggingface_hub import snapshot_download
7
  from config import Config
8
 
 
 
 
9
  # Model config
10
  REPO_ID = Config.IMAGE_CLASSIFIER_REPO_ID
11
  MODEL_DIR = Config.IMAGE_CLASSIFIER_MODEL_DIR
12
  WEIGHTS_PATH = os.path.join(MODEL_DIR, Config.IMAGE_CLASSIFIER_WEIGHTS_FILE)
13
  HF_TOKEN = Config.HF_TOKEN
14
 
15
- # Device info (for logging)
16
- gpus = tf.config.list_physical_devices("GPU")
17
- device = "cuda" if gpus else "cpu"
18
-
19
  # Global model reference
20
  _model_img = None
21
 
22
- # Custom layer used in the model
23
- class Cast(Layer):
24
- def call(self, inputs):
25
- return tf.cast(inputs, tf.float32)
26
-
27
  def warmup():
28
  global _model_img
29
  download_model_repo()
@@ -43,11 +35,17 @@ def load_model():
43
  if _model_img is not None:
44
  return _model_img
45
 
46
- print(f"{'GPU detected' if device == 'cuda' else 'No GPU detected'}, loading model on {device.upper()}.")
 
 
 
 
47
 
48
- _model_img = tf.keras.models.load_model(
49
- WEIGHTS_PATH, custom_objects={"Cast": Cast}
50
- )
 
 
51
  print("Model input shape:", _model_img.input_shape)
52
  return _model_img
53
 
 
1
  import os
2
  import shutil
3
  import logging
 
 
4
  from huggingface_hub import snapshot_download
5
  from config import Config
6
 
7
+ os.environ.setdefault("CUDA_VISIBLE_DEVICES", "-1")
8
+ os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "2")
9
+
10
  # Model config
11
  REPO_ID = Config.IMAGE_CLASSIFIER_REPO_ID
12
  MODEL_DIR = Config.IMAGE_CLASSIFIER_MODEL_DIR
13
  WEIGHTS_PATH = os.path.join(MODEL_DIR, Config.IMAGE_CLASSIFIER_WEIGHTS_FILE)
14
  HF_TOKEN = Config.HF_TOKEN
15
 
 
 
 
 
16
  # Global model reference
17
  _model_img = None
18
 
 
 
 
 
 
19
  def warmup():
20
  global _model_img
21
  download_model_repo()
 
35
  if _model_img is not None:
36
  return _model_img
37
 
38
+ import tensorflow as tf
39
+
40
+ class Cast(tf.keras.layers.Layer):
41
+ def call(self, inputs):
42
+ return tf.cast(inputs, tf.float32)
43
 
44
+ print("Loading image model on CPU.")
45
+ with tf.device("/CPU:0"):
46
+ _model_img = tf.keras.models.load_model(
47
+ WEIGHTS_PATH, custom_objects={"Cast": Cast}
48
+ )
49
  print("Model input shape:", _model_img.input_shape)
50
  return _model_img
51
 
features/real_forged_classifier/main.py DELETED
@@ -1,26 +0,0 @@
1
- from fastapi import FastAPI
2
- from routes import router as api_router
3
-
4
- # Initialize the FastAPI app
5
- app = FastAPI(
6
- title="Real vs. Fake Image Classification API",
7
- description="An API to classify images as real or forged using FFT and cnn.",
8
- version="1.0.0"
9
- )
10
-
11
- # Include the API router
12
- # All routes defined in routes.py will be available under the /api prefix
13
- app.include_router(api_router, prefix="/api", tags=["Classification"])
14
-
15
- @app.get("/", tags=["Root"])
16
- async def read_root():
17
- """
18
- A simple root endpoint to confirm the API is running.
19
- """
20
- return {"message": "Welcome to the Image Classification API. Go to /docs for the API documentation."}
21
-
22
- # To run this application:
23
- # 1. Make sure you have all dependencies from requirements.txt installed.
24
- # 2. Make sure the 'svm_model.joblib' file is in the same directory.
25
- # 3. Run the following command in your terminal:
26
- # uvicorn main:app --reload