haydpw commited on
Commit
91657e5
·
1 Parent(s): d9f4c27

uninstall tensorflow

Browse files
Files changed (2) hide show
  1. models/face_classifier.py +0 -54
  2. requirements.txt +0 -0
models/face_classifier.py CHANGED
@@ -1,16 +1,11 @@
1
  from keras._tf_keras.keras.models import load_model
2
- import keras
3
  import warnings
4
  import traceback
5
- import cv2
6
  import sys
7
- import tensorflow as tf
8
  import numpy as np
9
- import exceptions
10
  import os
11
  from PIL import Image
12
  from exceptions.NotFaceError import NotFaceError
13
- from inference_sdk import InferenceHTTPClient
14
  from transformers import pipeline, SegformerForSemanticSegmentation, SegformerImageProcessor, SegformerFeatureExtractor
15
 
16
  def warning_with_traceback(message, category, filename, lineno, file=None, line=None):
@@ -19,55 +14,6 @@ def warning_with_traceback(message, category, filename, lineno, file=None, line=
19
  log.write(warnings.formatwarning(message, category, filename, lineno, line))
20
 
21
  warnings.showwarning = warning_with_traceback
22
-
23
-
24
- @keras.saving.register_keras_serializable()
25
- class CustomPreprocessingLayer(tf.keras.layers.Layer):
26
- def __init__(self, input_shape, **kwargs):
27
- self.input_shape = input_shape
28
- super(CustomPreprocessingLayer, self).__init__(**kwargs)
29
-
30
- def build(self, input_shape):
31
- pass # No trainable weights to build
32
-
33
- def call(self, image_matrix):
34
- image = tf.convert_to_tensor(image_matrix, dtype=tf.int32)
35
- image = tf.image.resize(image, [self.input_shape[0], self.input_shape[1]])
36
- return image
37
- def get_config(self):
38
- config = super(CustomPreprocessingLayer, self).get_config()
39
- config.update({'input_shape': self.input_shape})
40
- return config
41
-
42
- @classmethod
43
- def from_config(cls, config):
44
- return cls(**config)
45
-
46
- class FaceClassifierModel:
47
- def __init__(self, client:InferenceHTTPClient, image_size=224, batcb_size=16):
48
- self.model = load_model("./models/efficientnet_face_detection.h5")
49
- self.image_size = image_size
50
- self.batch_size = batcb_size
51
- self.seed = 42
52
- self.client = client
53
-
54
- async def classify(self, image_bytes: str, confidence_threshold=0.5):
55
- tf.random.set_seed(self.seed)
56
- nparr = np.frombuffer(image_bytes, np.uint8)
57
-
58
- # Dekode array NumPy menjadi citra OpenCV
59
- image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
60
- image = cv2.resize(image, [self.image_size, self.image_size])
61
- image_expanded = tf.expand_dims(image,axis=0)
62
- image_batch = tf.data.Dataset.from_tensor_slices(image_expanded).batch(self.batch_size)
63
- pred = self.model.predict(image_batch)
64
- if pred[0][0] <= confidence_threshold:
65
- raise NotFaceError("Ini bukan wajah")
66
-
67
- # lanjut klasifikasi muka
68
- result = await self.client.infer_async(image, model_id="skinclassification-kyxvj/1")
69
- result["face_confidence"] = float(pred[0][0])
70
- return result
71
 
72
 
73
  class FaceSegmentationModel:
 
1
  from keras._tf_keras.keras.models import load_model
 
2
  import warnings
3
  import traceback
 
4
  import sys
 
5
  import numpy as np
 
6
  import os
7
  from PIL import Image
8
  from exceptions.NotFaceError import NotFaceError
 
9
  from transformers import pipeline, SegformerForSemanticSegmentation, SegformerImageProcessor, SegformerFeatureExtractor
10
 
11
  def warning_with_traceback(message, category, filename, lineno, file=None, line=None):
 
14
  log.write(warnings.formatwarning(message, category, filename, lineno, line))
15
 
16
  warnings.showwarning = warning_with_traceback
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
 
19
  class FaceSegmentationModel:
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ