gihakkk commited on
Commit
d814921
ยท
verified ยท
1 Parent(s): fba948b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +41 -8
README.md CHANGED
@@ -6,13 +6,46 @@ license: unknown
6
  ๋กœ๋งจ์Šค ์Šค์บ ์—์„œ ์นด๋ฉ”๋ผ์— ์ฃผ๋กœ ๋น„์ถฐ์ง„ ์‚ฌ์ง„์„ ์กฐ์‚ฌํ•ด ์ง‘์–ด๋„ฃ์–ด ์œ ์‚ฌ๋„ ํŒ๋‹จ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.
7
  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
8
  ```python
9
- def cnn_similarity_analysis(image):
10
- img_array = preprocess_image(image)
11
- reconstructed_img = cnn_model.predict(img_array)
12
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  try:
14
- psnr_value = calculate_psnr(img_array, reconstructed_img)
15
- return psnr_value > 18 # ์ž„๊ณ„๊ฐ’ ๊ธฐ์ค€ ์œ ์‚ฌ๋„ ํŒ๋‹จ
16
- except ValueError as e:
17
- return False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  ```
 
6
  ๋กœ๋งจ์Šค ์Šค์บ ์—์„œ ์นด๋ฉ”๋ผ์— ์ฃผ๋กœ ๋น„์ถฐ์ง„ ์‚ฌ์ง„์„ ์กฐ์‚ฌํ•ด ์ง‘์–ด๋„ฃ์–ด ์œ ์‚ฌ๋„ ํŒ๋‹จ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.
7
  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
8
  ```python
9
+ import tensorflow as tf
10
+ import numpy as np
11
+ from PIL import Image
12
+ import requests
13
+
14
+ # CNN ๋ชจ๋ธ ๋‹ค์šด๋กœ๋“œ ๋ฐ ๋กœ๋“œ
15
+ model_url = "https://huggingface.co/gihakkk/CNN_modle/resolve/main/cnn_similarity_model.keras"
16
+ model_path = "cnn_similarity_model.keras"
17
+
18
+ # ๋ชจ๋ธ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ
19
+ response = requests.get(model_url)
20
+ with open(model_path, "wb") as f:
21
+ f.write(response.content)
22
+
23
+ # Keras ๋ชจ๋ธ ๋กœ๋“œ
24
+ cnn_model = tf.keras.models.load_model(model_path)
25
+
26
+ # ์ด๋ฏธ์ง€ ์ „์ฒ˜๋ฆฌ ํ•จ์ˆ˜
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
  ```