π¦ Likelion AI SCHOOL7 πΆπ€± μΌμ€μΌμ€ν3 9μ‘° μ€9οΈβ£μ€9οΈβ£ ν
name | github | velog&blog |
---|---|---|
κΉμμ§π | ||
μ΄μ μ | ||
μ‘°μμ¬ | ||
μμ’ μ° | ||
κΆνμ€ |
number | title | link | bestscore |
---|---|---|---|
1 | π₯¬ Prediction of bok choy growth | https://dacon.io/competitions/official/235961/overview/description | private mse 17.53 |
2 | π· Face Mask Classification | https://www.kaggle.com/datasets/dhruvmak/face-mask-detection | accuracy 0.97 |
3 | π Sentences type Classification | https://dacon.io/competitions/official/236037/overview/description | private accuracy 0.7559 |
π dacon AI κ²½μ§λν : μ²κ²½μ± μ±μ₯λ₯ μμΈ‘νκΈ°
μ£Όμ : https://dacon.io/competitions/official/235961/overview/description
π notion : https://www.notion.so/MINI5-AI-b031d68247e24a30b192b24c522284d1
4μ°¨ μ°μ νλͺ μλλ₯Ό λ§μ λμ λΆμΌμμλ AI κΈ°μ μ΄ λ리 μ¬μ©λμ΄ IT κΈ°μ μ λμν μ€λ§νΈν λ± λμ± ν¨μ¨μ μΈ μλ¬Ό μ¬λ°°κ° κ°λ₯ν΄μ§κ³ μμ΅λλ€. μλ¬Όμ ν¨μ¨μ μΈ μμ‘μ μν μ΅μ μ νκ²½μ λμΆνλ€λ©΄ μλ¬Ό μ¬λ°°μ ν° λμμ΄ λ κ²μ΄λ©°, μ²κ²½μ± λΏλ§ μλ λͺ¨λ μλ¬Ό μ¬λ°°μ¨μ΄ μ’μμ§ κ²μ λλ€. λ―Έλμ μλ¬Ό μ¬λ°°μμλ μ΄ λ°μ΄ν°λ₯Ό κ°μ§κ³ μΈκ³΅μ§λ₯μ μ΄μ©νμ¬ μλ¬Όλ³ λ§μΆ€ν μ루μ μ λμ μΈλ€μ΄ νΈλ¦¬νκ³ μΉκ·Όνκ² μν μμμ νμ©νλ 첫 κ±Έμμ λ΄λμ μ μμ κ²μ λλ€.λ°λΌμ, μΈκ³΅μ§λ₯(AI)μ νμ©νμ¬ κ΅λ΄ κ³ μ μλ¬Ό μμμμ μ μ©ν μ²μ°λ¬Ό μμ¬λ₯Ό νμνκ³ , κ·Έ ν¨λ₯κ³Ό νμ± λ±μ λν΄ μ°κ΅¬νλ κ²μ΄ λͺ©νμ
λλ€.
μ€μ AIλ₯Ό μ΄μ©ν μλ¬Όμ μ¬λ°°νλ μ€λ§νΈνκ³Ό κ°μ κ³³μ μ μ©νκ² μ¬μ©λ κ²μ
λλ€.
dacon μ²κ²½μ± μμΈ‘ λ°μ΄ν° : https://dacon.io/competitions/official/235961/data
π train input dataset[folder]
μ΄ 58κ° μ²κ²½μ± μΌμ΄μ€λ₯Ό κ° μ²κ²½μ± μΌμ΄μ€ λ³ νκ²½ λ°μ΄ν°(1λΆ κ°κ²©)μΌλ‘ ꡬμ±λμ΄ μμ
π train target dataset[folder]
μ΄ 58κ° μ²κ²½μ± μΌμ΄μ€λ₯Ό rate columnμ κ° μ²κ²½μ± μΌμ΄μ€ λ³ μ λ©΄μ μ¦κ°λ₯ (1μΌ κ°κ²©)λ‘ κ΅¬μ±λμ΄ μμ
π train(input+target) shape
train(input+target) (1813, 43)
test(input+target) (195, 43)
1οΈβ£ λ΄λΆμ¨λκ΄μΈ‘μΉ, λ΄λΆμ΅λκ΄μΈ‘μΉ, μ΄μΆμ κ΄λ, μλ³ rate
2οΈβ£ μ μ, μ²μ, λ°±μ, μ΄μΆ μΆμ κ΄λ λ³ rate
λ°±μκ³Ό μ΄μΆλ 100μμ, μ μκ³Ό μ²μμ 0μμ μ±μ₯λ₯ μ΄ λλ€.
3οΈβ£ ECμ CO2μ λλ°©μν
ECκ΄μΈ‘μΉκ° ν΄μλ‘ λλ°©μνλ μ μμΌλ©°, λ°λλ‘ μμμλ‘ λλ°©μνλ λμ κ²μ νμΈν μ μλ€.
4οΈβ£ κ° CASE λ³ μλ©΄μ μ¦κ°λ₯ (rate) λ³ν
λΆν¬λ₯Ό μΌμ νκ² λ§λ€κΈ° μν Scaling κ³Όμ μ΄ νμν¨μ΄ 보μλ€.
π Scaling - RobustScaler
from sklearn.preprocessing import RobustScaler
rb = RobustScaler()
train_X = rb.fit_transform(train_X)
test_X = rb.transform(test_X)
π Tensorflow
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(units=128, input_shape=[input_shape]),
tf.keras.layers.Dense(128, activation='selu'),
tf.keras.layers.Dropout(0.1),
tf.keras.layers.Dense(1)
])
optimizer = tf.keras.optimizers.RMSprop(0.001)
model.compile(optimizer=optimizer,
loss=["mae", "mse"],
metrics=["mae", "mse"])
π Pytorch
linear1 = torch.nn.Linear(train_X.shape[1], 512, bias=True)
linear3 = torch.nn.Linear(512, 256, bias=True)
linear4 = torch.nn.Linear(256, 128, bias=True)
linear5 = torch.nn.Linear(128, 64, bias=True)
linear6 = torch.nn.Linear(64, 32, bias=True)
linear7 = torch.nn.Linear(32, 10, bias=True)
linear8 = torch.nn.Linear(10, 1, bias=True)
relu = torch.nn.ReLU()
dropout = torch.nn.Dropout(p=0.1)
model = torch.nn.Sequential(linear1,relu,
linear3,relu,
linear4, relu,
linear5, relu,
linear6, relu,
linear7, relu,
linear8).to(device)
# nn ν¨ν€μ§λ₯Ό μ¬μ©νμ¬ λͺ¨λΈκ³Ό μμ€ ν¨μλ₯Ό μ μν©λλ€.
loss_fn = torch.nn.MSELoss().to(device)
optimizer = optim.Adam(model.parameters(), lr=0.0005)
# κ°μ€μΉ μ΄κΈ°ν
torch.nn.init.xavier_normal_(linear1.weight)
torch.nn.init.xavier_normal_(linear2.weight)
torch.nn.init.xavier_normal_(linear3.weight)
torch.nn.init.xavier_normal_(linear4.weight)
torch.nn.init.xavier_normal_(linear5.weight)
torch.nn.init.xavier_normal_(linear6.weight)
torch.nn.init.xavier_normal_(linear7.weight)
torch.nn.init.xavier_normal_(linear8.weight)
Parameter containing:
tensor([[-0.1239, 0.3789, -0.2748, 0.2951, 0.0612, 0.2898, 0.2660, -0.4028,
-1.1738, 0.6484]], requires_grad=True)
π LSTM
class BaseModel(nn.Module):
def __init__(self):
super(BaseModel, self).__init__()
self.lstm = nn.LSTM(input_size=train_X.shape[1], hidden_size=256, batch_first=True, bidirectional=False) # LSTM λ©λͺ¨λ¦¬ μΆκ°
self.dense = nn.Sequential(
# nn.Linear(256, 10 , torch.nn.ReLU()),
# Layer μΆκ°
nn.Linear(256, 128, torch.nn.ReLU()),
nn.Linear(128, 64, torch.nn.ReLU()),
nn.Linear(64, 32, torch.nn.ReLU()),
nn.Linear(32, 10, torch.nn.ReLU()),
nn.Linear(10, 1)
)
self.dropout = nn.Dropout(0.2)
def forward(self, x):
hidden, _ = self.lstm(x)
x = self.dropout(hidden)
output = self.dense(hidden)
return output
model = BaseModel()
model.eval()
loss_fn = torch.nn.MSELoss().to(device)
optimizer = optim.Adam(model.parameters(), lr=0.0005)
πTensorflow
public : 17.91, private : 17.53
π Pytorch
public : 19.2138, private : 18.009
πLSTM
public : 21.5578 / private 22.5213
π Kaggle AI κ²½μ§λν : λ§μ€ν¬ μ°©μ©/λ―Έμ°©μ© λΆλ₯
μ£Όμ : https://www.kaggle.com/datasets/dhruvmak/face-mask-detection
π notion : https://www.notion.so/MINI6-Mask_or_No_Mask-Classification-a7d66cebd161444180e9024e13be2f98#35d0f4877a1f4aa3bd9a0719fc5bea2d
π streamlit : https://seul1230-mask-classification-main-pqg0f0.streamlit.app/
π streamlit : https://imngooh-mini-streamlit-app-82wtn0.streamlit.app/
kaggle λ§μ€ν¬ μ°©μ© μ¬λΆ μ΄λ―Έμ§ λ°μ΄ν° : https://www.kaggle.com/datasets/dhruvmak/face-mask-detection
π with mask[folder]
μ΄ 220κ°μ λ§μ€ν¬ μ°©μ©ν μ¬λλ€μ μ΄λ―Έμ§
π without mask[folder]
μ΄ 220κ°μ λ§μ€ν¬ λ―Έμ°©μ©ν μ¬λλ€μ μ΄λ―Έμ§
π train/valid/test shape
train_df (281, 2)
val_df (71, 2)
test_df (88, 2)
β Tensorflowλ₯Ό μ΄μ©ν λͺ¨λΈλ§ β
π Resnet152V
# imagenetμΌλ‘ pre-trained λ κ°μ€μΉ κ° μ μ©
md = ResNet152V2(include_top=False, pooling='max',
weights='imagenet', input_shape=(height, width, 3))
md.trainable=False
model = models.Sequential()
model.add(md)
model.add(layers.Dense(1, activation = 'sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
early_stop = EarlyStopping(patience=5)
history = model.fit(train_datagen, epochs=20,
validation_data=val_datagen,
validation_steps=len(val_datagen),
callbacks = [early_stop])
π VGG19
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Conv2D, MaxPool2D, Flatten
from tensorflow.keras.applications import vgg19
vgg = vgg19.VGG19(
include_top = False,
weights = 'imagenet',
input_shape = (height, width, 3)
)
model = Sequential()
model.add(vgg)
model.add(Flatten())
model.add(Dense(1, activation = 'sigmoid'))
model.compile(
optimizer = 'adam',
loss = 'binary_crossentropy',
metrics = ['accuracy']
)
from tensorflow.keras.callbacks import EarlyStopping
early_stop = EarlyStopping(monitor = 'val_loss', patience = 10)
history = model.fit(
train_dataset,
epochs = 100,
validation_data = valid_dataset,
callbacks = [early_stop]
π DenseNet121
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Conv2D, MaxPool2D, Flatten
from tensorflow.keras.applications import densenet
densenet = densenet.DenseNet121(
include_top = False,
weights = 'imagenet',
input_shape = (height, width, 3),
pooling = 'avg'
)
modeld = Sequential()
modeld.add(densenet)
modeld.add(Flatten())
modeld.add(Dense(1, activation = 'sigmoid'))
modeld.compile(
optimizer = 'adam',
loss = 'binary_crossentropy',
metrics = ['accuracy']
)
from tensorflow.keras.callbacks import EarlyStopping
early_stop = EarlyStopping(monitor = 'val_loss', patience = 10)
history = modeld.fit(
train_dataset,
epochs = 100,
validation_data = valid_dataset,
callbacks = [early_stop]
)
π νμλ€μ μ΄λ―Έμ§λ₯Ό μ΄μ©ν λ§μ€ν¬ μ°©μ©/λ―Έμ°©μ© μμΈ‘
π dacon AI κ²½μ§λν : λ¬Έμ₯ μ ν λΆλ₯νκΈ°
μ£Όμ : https://dacon.io/competitions/official/236037/overview/description
π notion : https://www.notion.so/Dacon-AI-54fe914d79584be2a7bd9404ee6fa9a5
ν루 μ’ μΌ ν λ§λλ νμ§ μλ λ μ μμν μ μμ§λ§, ν κΈμλ μ½μ§ μλ λ μ μμν μ μλ κ²μ²λΌ μ°λ¦¬λ μλ§μ λ¬Έμ₯κ³Ό κΈ μμ λλ¬μΈμ¬ μ΄κ³ μλ€. νΉνλ μ½λ‘λ19 μ΄ν, μ°λ¦¬ μ¬νμμ μ¨λΌμΈκ³Ό λΉλλ©΄ μν΅μ΄ μ£Όλ κ΅λ₯ λ°©μμ΄ λμλ€. κ·Έλ§νΌ μ°λ¦¬λ μ΄μ 보λ€λ λ λ§μ λ¬Έμ₯μ μ½κ³ μ°λ©° μΈμκ³Ό μν΅νκ³ μλ€. μ΄μ²λΌ μλ§μ κΈλ€μ AI λͺ¨λΈμ νμ©ν΄ νμ΅νκ³ , λΉ λ₯΄κ² λΆλ₯ν μ μλ€λ©΄ μ°λ¦¬λ λ μ κ΅νκ² λΆλ₯λ μ 보λ₯Ό μ»κ³ , μ΄λ₯Ό ν΅ν΄ μΈμ΄κ° μ°μ΄λ λͺ¨λ μμμμ λ³΄λ€ μ¬μ©μ μΉνμ μΈ μλΉμ€λ₯Ό κ²½νν μ μκ² λ κ²μ΄λ€.λ°λΌμ, ν λ° λ λμκ° νκ΅μ΄ μΈκ³΅μ§λ₯ κΈ°μ κ³ λνμ λ°νμ λ§λ ¨ν μ μλλ‘ μ°½μμ μΈ λ¬Έμ₯ μ ν λΆλ₯ AI λͺ¨λΈμ λ§λλ κ²μ΄ λͺ©νμ΄λ€.
dacon μ²κ²½μ± μμΈ‘ λ°μ΄ν° : https://dacon.io/competitions/official/236037/data
π train dataset
λ¬Έμ₯μ λ°λ₯Έ μ ν, κ·Ήμ±, μμ , νμ€μ±μ΄ ꡬλΆλμ΄ μμ (μ΄ 72κ° μ’
λ₯μ Class μ‘΄μ¬)
π train dataset
μ΄ 7090 λ¬Έμ₯μΌλ‘ ꡬμ±λμ΄ μμ
π train/test shape
train (16541, 7)
test (7090, 2)
1οΈβ£ κ° labelμ λΉλμ μκ°ν
κ·Ήμ±, μ ν, νμ€μ±μ ν κ³³μΌλ‘ μΉμ°μ³μ§ labelμ΄ μλ€.
μ΄μ λ°λ₯Έ ν΄κ²°μ±
μ μκ°ν΄μΌ ν κ²μ΄λ€.
2οΈβ£ νλλ‘ ν΅ν©ν labelμ λΉλμ μκ°ν
κ° ν΄λμ€ μ¬μ΄μμ λΆκ· νμ΄ μΌμ΄λ¨μ μ μ μλ€.
π Tensorflow
early_stop = EarlyStopping(monitor='val_loss', patience=5)
embedding_dim = 256
def Model(label):
n_class = train_labels[label].shape[1]
# λͺ¨λΈ μ μ
model = Sequential()
model.add(Embedding(input_dim = 77426,
output_dim = embedding_dim,
input_length = 80))
model.add(Bidirectional(LSTM(64, return_sequences=True)))
model.add(Bidirectional(LSTM(64, return_sequences=True)))
model.add(LSTM(64))
model.add(Dense(64, activation = 'relu'))
model.add(Dense(n_class, activation = 'softmax'))
model.compile(optimizer = 'adam',
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
# λͺ¨λΈ μ머리
display(model.summary())
# λͺ¨λΈ νΌν
history = model.fit(train_vec, train_labels[label], epochs = 100, validation_data = (val_vec, val_labels[label]), callbacks = [early_stop])
df_hist = pd.DataFrame(history.history)
print('*'*5, 'νμ΅μλ£', '*'*5)
df_hist[['loss','val_loss']].plot()
df_hist[['accuracy','val_accuracy']].plot()
# λͺ¨λΈ νκ°
print('valid νκ° κ²°κ³Ό')
model.evaluate(val_vec, val_labels[label])
# μμΈ‘
y_pred = model.predict(test_vec)
y_predict = np.argmax(y_pred, axis = 1)
return y_predict
π pytorch
class BaseModel(nn.Module):
def __init__(self, input_dim=9351):
super(BaseModel, self).__init__()
self.feature_extract = nn.Sequential(
nn.Linear(in_features=input_dim, out_features=1024),
nn.BatchNorm1d(1024),
nn.LeakyReLU(),
nn.Linear(in_features=1024, out_features=1024),
nn.BatchNorm1d(1024),
nn.LeakyReLU(),
nn.Linear(in_features=1024, out_features=512),
nn.BatchNorm1d(512),
nn.LeakyReLU(),
)
self.type_classifier = nn.Sequential(
nn.Dropout(p=0.3),
nn.Linear(in_features=512, out_features=4),
)
self.polarity_classifier = nn.Sequential(
nn.Dropout(p=0.3),
nn.Linear(in_features=512, out_features=3),
)
self.tense_classifier = nn.Sequential(
nn.Dropout(p=0.3),
nn.Linear(in_features=512, out_features=3),
)
self.certainty_classifier = nn.Sequential(
nn.Dropout(p=0.3),
nn.Linear(in_features=512, out_features=2),
)
def forward(self, x):
x = self.feature_extract(x)
# λ¬Έμ₯ μ ν, κ·Ήμ±, μμ , νμ€μ±μ κ°κ° λΆλ₯
type_output = self.type_classifier(x)
polarity_output = self.polarity_classifier(x)
tense_output = self.tense_classifier(x)
certainty_output = self.certainty_classifier(x)
return type_output, polarity_output, tense_output, certainty_output
π Tensorflow : 0.5794
π pytorch(baseline) : 0.5362
π best score : 0.7559 (λνκ° λλμ§ μμ λͺ¨λΈμ 미곡κ°)