gihakkk commited on
Commit
914790b
โ€ข
1 Parent(s): d814921

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +17 -11
README.md CHANGED
@@ -27,25 +27,31 @@ cnn_model = tf.keras.models.load_model(model_path)
27
  def preprocess_image(image_path):
28
  try:
29
  img = Image.open(image_path).convert('RGB')
30
- img = img.resize((224, 224)) # ๋ชจ๋ธ์ด ์š”๊ตฌํ•˜๋Š” ํฌ๊ธฐ
31
- img_array = np.array(img) / 255.0
32
- img_array = np.expand_dims(img_array, axis=0)
33
  return img_array
34
  except Exception as e:
35
  print(f"Error processing image: {e}")
 
36
 
37
- # ์ด๋ฏธ์ง€ ์˜ˆ์ธก ํ•จ์ˆ˜
38
- def predict_image(image_path):
39
  img_array = preprocess_image(image_path)
40
  if img_array is not None:
41
- predictions = cnn_model.predict(img_array)
42
- return predictions
 
 
 
 
43
  else:
44
- return "Image preprocessing failed."
45
 
46
  # ํ…Œ์ŠคํŠธ ์ด๋ฏธ์ง€ ์˜ˆ์ธก
47
- image_path = r'์ด๋ฏธ์ง€ ์ž…๋ ฅ ๊ฒฝ๋กœ' #์›ํ•˜๋Š” ์ด๋ฏธ์ง€ ์œ„์น˜
48
- prediction_result = predict_image(image_path)
49
- print("Prediction:", prediction_result)
 
50
 
51
  ```
 
27
  def preprocess_image(image_path):
28
  try:
29
  img = Image.open(image_path).convert('RGB')
30
+ img = img.resize((152, 152)) # ๋ชจ๋ธ์ด ์š”๊ตฌํ•˜๋Š” ํฌ๊ธฐ
31
+ img_array = np.array(img) / 255.0 # ์ด๋ฏธ์ง€๋ฅผ 0-1 ์‚ฌ์ด๋กœ ์ •๊ทœํ™”
32
+ img_array = np.expand_dims(img_array, axis=0) # ๋ฐฐ์น˜ ์ฐจ์› ์ถ”๊ฐ€
33
  return img_array
34
  except Exception as e:
35
  print(f"Error processing image: {e}")
36
+ return None
37
 
38
+ # ์œ ์‚ฌ๋„ ์˜ˆ์ธก ํ•จ์ˆ˜
39
+ def predict_similarity(image_path):
40
  img_array = preprocess_image(image_path)
41
  if img_array is not None:
42
+ predictions = cnn_model.predict(img_array) # ๋ชจ๋ธ์„ ํ†ตํ•ด ์˜ˆ์ธก
43
+ similarity_score = np.mean(predictions) # ์œ ์‚ฌ๋„ ์ ์ˆ˜์˜ ํ‰๊ท  ๊ณ„์‚ฐ
44
+ if similarity_score > 0.5: # ์ž„๊ณ„๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ์œ ์‚ฌ๋„ ํŒ๋‹จ
45
+ return "๋กœ๋งจ์Šค ์Šค์บ  ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค."
46
+ else:
47
+ return "๋กœ๋งจ์Šค ์Šค์บ  ์ด๋ฏธ์ง€๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค."
48
  else:
49
+ return "์ด๋ฏธ์ง€ ์ „์ฒ˜๋ฆฌ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."
50
 
51
  # ํ…Œ์ŠคํŠธ ์ด๋ฏธ์ง€ ์˜ˆ์ธก
52
+ image_path = r'์‚ฌ์ง„ ์œ„์น˜ ์ž…๋ ฅ' # ํ…Œ์ŠคํŠธํ•  ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ
53
+ result = predict_similarity(image_path)
54
+ print(result)
55
+
56
 
57
  ```