Stream Serving

Data Subscriber

data_subscriber.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
from dotenv import load_dotenv

from json import loads

import psycopg2
import requests
from kafka import KafkaConsumer


def create_table(db_connect):
create_table_query = """
CREATE TABLE IF NOT EXISTS breast_cancer_prediction (
id SERIAL PRIMARY KEY,
timestamp timestamp,
breast_cancer_class int
);"""
print(create_table_query)
with db_connect.cursor() as cur:
cur.execute(create_table_query)
db_connect.commit()


def insert_data(db_connect, data):
insert_row_query = f"""
INSERT INTO breast_cancer_prediction
(timestamp, breast_cancer_class)
VALUES (
'{data["timestamp"]}',
{data["target"]}
);"""
print(insert_row_query)
with db_connect.cursor() as cur:
cur.execute(insert_row_query)
db_connect.commit()


def subscribe_data(db_connect, consumer):
for msg in consumer:
print(
f"Topic : {msg.topic}\n"
f"Partition : {msg.partition}\n"
f"Offset : {msg.offset}\n"
f"Key : {msg.key}\n"
f"Value : {msg.value}\n",
)

msg.value["payload"].pop("id")
msg.value["payload"].pop("target")
ts = msg.value["payload"].pop("timestamp")

response = requests.post(
url="http://api-with-model:8000/predict",
json=msg.value["payload"],
headers={"Content-Type": "application/json"},
).json()
response["timestamp"] = ts
insert_data(db_connect, response)


if __name__ == "__main__":
load_dotenv()
db_connect = psycopg2.connect(
user=os.environ.get("POSTGRES_USER"),
password=os.environ.get("POSTGRES_PASSWORD"),
host=os.environ.get("POSTGRES_HOST"),
port=5432,
database=os.environ.get("POSTGRES_DB"),
)
create_table(db_connect)

consumer = KafkaConsumer(
"postgres-source-breast_cancer_data",
bootstrap_servers="broker:29092",
auto_offset_reset="earliest",
group_id="breast_cancer_data-consumer-group",
value_deserializer=lambda x: loads(x),
)
subscribe_data(db_connect, consumer)
Read more »

Introduction

논문의 저자가 제공하거나 논문을 참고하여 개발된 모델은 보통 config 파일 (e.g. config.yaml, config.py)이 존재하고, 해당 파일을 통해 이렇게 모델 구조를 변경할 수 있다.
하지만 기존의 소스에 본인이 원하는 모델 구조가 없다면 어떻게 개발하는지, 그리고 기존에 없던 레이어를 어떻게 훈련하면 좋을지 알아보자.
이 글에서는 이 논문을 기반으로 개발된 모델인 whai362/pan_pp.pytorch를 기준으로 개발하겠다.
간단한 목표 설정을 해보기 위해 대략적인 모델의 설명을 진행하겠다.

PAN++

PAN++는 STR (Scene Text Recognition)을 위해 개발되었지만, 본 글에서는 STD (Scene Text Detection) 부분까지만 사용하며 해당 부분은 아래와 같이 진행된다.

  1. Feature Extraction
    • Layer: Backbone (ResNet)
    • Output: Feature map
  2. Feature Fusion
    • Layer: FPEM (Feature Pyramid Enhancement Module)
    • Output: Enhanced feature map
  3. Detection
    • Layer: Detection Head
    • Output: Text region, text kernel, instance vector
  4. Post-processing (Pixel Aggregation, PA)
    • Output: Axis of bbox (bounding box)

Goal

  • FPEM의 stack 수 편집
    • 원문 코드: 2 stacked FPEMs 사용
    • 목표: 4 stacked FPEMs
  • Fine-tuning
    • 목표: 추가된 2 stacked FPEMs 계층만을 훈련
Read more »

킹받는 호돌이

received-king

Introduction

안녕하세요, 저는 2023년 2월 22일에 건국대학교 기계설계학과에서 석사학위를 취득했고 2023년 2월 1일에 전문연구요원으로 편입하기 위해 AgileSoDA에 입사하였습니다.
학위과정을 거친 모든 연구자 분들이 공식 문서나 복잡한 서류들을 자주 읽어서 헤메는 분들이 많진 않겠지만, 제 블로그를 통해 전문연구요원을 준비하시는 석, 박사과정 분들과 현재 재직 중이신 전문연구요원 분들에게 작은 도움이 됐으면 합니다.
먼저 본격적인 전문연구요원 편입 과정에 앞서 학위 수여 전 유의해야할 사항에 대해 알려드리겠습니다.

Read more »

Kafka System

connect.Dockerfile
1
2
3
4
5
6
7
FROM confluentinc/cp-kafka-connect:7.3.0

ENV CONNECT_PLUGIN_PATH="/usr/share/java,/usr/share/confluent-hub-components"

RUN confluent-hub install --no-prompt snowflakeinc/snowflake-kafka-connector:1.5.5 &&\
confluent-hub install --no-prompt confluentinc/kafka-connect-jdbc:10.2.2 &&\
confluent-hub install --no-prompt confluentinc/kafka-connect-json-schema-converter:7.3.0
Read more »