ํฐ์คํ ๋ฆฌ ๋ทฐ
์ด๋ฏธ์ง๋ฅผ ๊ตฌ๊ธ ํด๋ผ์ฐ๋ ์คํ ๋ฆฌ์ง์ ์ฌ๋ฆด๋ ํ์ผ์ ํฝ์ ๊ฐ์ด ์ ์ฒด ์์์ ์ฝ 9%๊ฐ ๋ณ๊ฒฝ๋๋ค. ์ด๋ก ์ธํด ์ด๋ฏธ์ง๋ฅผ ํตํด inference๋ฅผ ์ํํ ๋ ๊ฐ์ด ๋ฌ๋ผ์ง๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค๐ฃ ์ด๋ฏธ์ง์ ์์ ํ๋ํ๋์ ํฐ ์ํฅ์ ๋ฐ๋ ์ด๋ฏธ์ง ๋ถ๋ฅ ๋ชจ๋ธ์ด๊ธฐ ๋๋ฌธ์ ์ด ๋ถ๋ถ์ ๋น ๋ฅด๊ฒ ์์ ํด์ผ ํ๋ค.
# ํ์ผ์ด ๊ฐ์ง ์์
AssertionError:
Arrays are not equal to 7 decimals
Mismatched elements: 215247 / 2362368 (9.11%)
Max absolute difference: 255
Max relative difference: 255.
x: array([[[ 0, 0, 4],
[ 5, 6, 10],
[ 8, 9, 13],...
y: array([[[ 0, 0, 4],
[ 5, 6, 10],
[ 8, 9, 13],...
gcp์ ์ ๋ก๋ํ ๋ ๋ฐ์ด๋๋ฆฌ ํ์ผ๋ก ๋ณํํด ์ ๋ก๋ํ๋๋ฐ ์ด ๋ถ๋ถ์ด ๋ฌธ์ ์ผ๊น? ํ์ผ์ ์ฌ๋ฆฌ๊ณ ๋ค์ด๋ฐ์์ ๋ ๊ฐ์ด ๋ณํ๋์ ๊ฒ์ผ๋ก ์ถ์ธกํ๊ณ ๋ก์ปฌ์์ ํ ์คํธํด๋ดค๋ค.
# ๋ฐ์ด๋๋ฆฌ ํ์ผ๋ก ๋ณํ ํ ์ ์ฅ
image_bytes = cv2.imencode(".jpg", image)[1].tostring()
with open('test.jpg', 'wb') as f:
f.write(image_bytes)
# ๋ฐ์ด๋๋ฆฌ ํ์ผ์ ์ฝ์ ํ ๋ค์ ๋์ฝ๋ฉ
with open('test.jpg', 'rb') as f:
new_image_bytes = f.read()
new_image = cv2.imdecode(np.frombuffer(new_image_bytes, np.uint8), cv2.IMREAD_COLOR)
# ์ด๋ฏธ์ง ํ์ผ ๋น๊ต
np.testing.assert_equal(image, new_image)
# ์ญ์๋ ์๋ฌ๊ฐ ๋ฌ๋ค.
AssertionError:
Arrays are not equal
Mismatched elements: 215247 / 2362368 (9.11%)
Max absolute difference: 255
Max relative difference: 255.
x: array([[[ 0, 0, 4],
[ 5, 6, 10],
[ 8, 9, 13],...
y: array([[[ 0, 0, 4],
[ 5, 6, 10],
[ 8, 9, 13],...
์ญ์๋ ํ์ผ์ด ์ธ์ฝ๋ฉ ํ ๋์ฝ๋ฉํ๋ ๊ณผ์ ์์ ๋ฐ์ํ ๋ฌธ์ ์๋ค. ๊ทธ๋ ๋ค๋ฉด ์๋ณธ ์ด๋ฏธ์ง์ ์ธ์ฝ๋ฉ, ๋์ฝ๋ฉ๋ ์ด๋ฏธ์ง๊ฐ ๋ฐ๋์ง ์๊ฒ ํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผํ ๊น? ์ด์ ๊ฐ ๋ฌด์์ผ๊น? ์์ธ์ ์ฐพ์๋ณด๋ ํ์ผ ์์ถ ์ jpg ํฌ๋งท์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ด์๋ค.
jpeg๋ ์์ค ์์ถ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์ธ์ฝ๋ฉํ๋ ๊ณผ์ ์์ ์์ค์ด ๋ฐ์ํ๊ณ ์ธ์ฝ๋ฉ, ๋์ฝ๋ฉํ๋ ๊ณผ์ ์์ ์์ค์ด ๊ณ์ ์์ด๊ฒ ๋์ด ์๋ณธ ์ด๋ฏธ์ง์ ์ธ์ฝ๋ฉ ํ ๋์ฝ๋ฉ๋ ์ด๋ฏธ์ง ๊ฐ์ด ์์ ํ ๋์ผํ์ง ์๊ฒ ๋๋ค๋ ๊ฒ์ด๋ค. ํด๊ฒฐํ๊ธฐ ์ํด์ png ํฌ๋งท์ ์ฌ์ฉํ๋ฉด ๋๋ค. png๋ ์ฉ๋์ด ์ฆ๊ฐํ์ง๋ง ๋น์์ค ์์ถ์ด๊ธฐ ๋๋ฌธ์ ํ์ผ์ ์์ธกํ ๋ ์์ค์ด ๋ฐ์ํ์ง ์๋๋ค๊ณ ํ๋ค. ์ด๋ฅผ ํ์ธํ๊ธฐ ์ํด png ํฌ๋งท์ผ๋ก ์ธ์ฝ๋ฉํ ๋ค ๋์ฝ๋ฉํ ์ด๋ฏธ์ง์ ์๋ณธ ์ด๋ฏธ์ง๋ฅผ ๋น๊ตํ๋ ์ฝ๋๋ฅผ ์์ฑํด๋ณด์.
image_bytes = cv2.imencode(".png", image)[1].tostring()
with open('test.jpg', 'wb') as f:
f.write(image_bytes)
with open('test.jpg', 'rb') as f:
new_image_bytes = f.read()
new_image = cv2.imdecode(np.frombuffer(new_image_bytes, np.uint8), cv2.IMREAD_COLOR)
np.testing.assert_almost_equal(image, new_image)
assertionerror ์์ด ๋์ผํ ๊ฐ์์ ํ์ธํ ์ ์์๋ค. ๋ฌธ์ ๊ฐ ํด๊ฒฐ ๋์ผ๋ ๋ค์ ๋์์์ google cloud storage์ ์ ๋ก๋ํ๋ ์ฝ๋์ ์ ์ฉํด๋ณด๋ฉด ์๋์ ๊ฐ๋ค.
# ์
๋ก๋ ํ๊ธฐ
import os
from google.cloud import storage
from google.cloud.storage import Blob
bucket_name = ''
CREDENTIAL_KEY = ''
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = CREDENTIAL_KEY
# ์ด๋ฏธ์ง ์
๋ก๋
storage_client = storage.Client.from_service_account_json(CREDENTIAL_KEY)
bucket = storage_client.get_bucket(bucket_name)
image_bytes = cv2.imencode(".png", image)[1].tostring()
blob = Blob('image_name', bucket)
blob.upload_from_string(data=image_bytes, content_type="image/png")
# ์ด๋ฏธ์ง ๋ค์ด
blob = bucket.get_blob('image_name')
encoded_img = np.frombuffer(blob.download_as_string(), dtype=np.uint8)
test_image = cv2.imdecode(encoded_img, cv2.IMREAD_COLOR)
# ๊ฒฐ๊ณผ ํ์ธ
np.testing.assert_equal(test_image, image)
์ฐธ๊ณ ํ ์๋ฃ
'๐ป Dev' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ docker cache ์ญ์ ํ๊ธฐ (0) | 2024.05.02 |
---|---|
๐โโ๏ธ [python] ray๋ก ์นผํด๋ฅผ ํด๋ณด์ (0) | 2024.05.02 |
๐ผ [python] pandas dataframe์ ๊ฑฐ์ ๋ชจ๋ ๊ฒ (1) | 2024.05.02 |
๐ณ ์ด์ ๋ docker๋ฅผ ํด์ผํ ๋.. (0) | 2024.04.22 |
๐ [Git]forkํ branch ์ต์ ๋ฒ์ ์ผ๋ก ์ ๋ฐ์ดํธํ๊ธฐ (0) | 2024.04.17 |
- ์ฑ ๋ฆฌ๋ทฐ
- vscode
- ๋จธ์ ๋ฌ๋ ์ด๋ก
- ํ๊ณ
- Multiprocessing
- linux
- Generative Model
- tmux
- GIT
- ๋ ํ๊ฐ
- ๋ฒ ์ด์ฆ ์ ๋ฆฌ
- ๊ธ๋
- python
- ๊ฐ๋ฐ์
- Computer Vision
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- Total
- Today
- Yesterday