mirror of
https://github.com/jung-geun/PSO.git
synced 2025-12-20 04:50:45 +09:00
23-07-07
dev container 설정 - tqdm + tensorflow 자동 설치 env name = pso 로 자동 생성
This commit is contained in:
32
iris_tf.py
32
iris_tf.py
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
||||
|
||||
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
@@ -10,23 +11,23 @@ if gpus:
|
||||
tf.config.experimental.set_memory_growth(gpus[0], True)
|
||||
except RuntimeError as e:
|
||||
print(e)
|
||||
|
||||
|
||||
from sklearn.datasets import load_iris
|
||||
from sklearn.model_selection import train_test_split
|
||||
from tensorflow import keras
|
||||
from tensorflow.keras import layers
|
||||
from tensorflow.keras.models import Sequential
|
||||
|
||||
from sklearn.datasets import load_iris
|
||||
from sklearn.model_selection import train_test_split
|
||||
|
||||
|
||||
def make_model():
|
||||
model = Sequential()
|
||||
model.add(layers.Dense(10, activation='relu', input_shape=(4,)))
|
||||
model.add(layers.Dense(10, activation='relu'))
|
||||
model.add(layers.Dense(3, activation='softmax'))
|
||||
model.add(layers.Dense(10, activation="relu", input_shape=(4,)))
|
||||
model.add(layers.Dense(10, activation="relu"))
|
||||
model.add(layers.Dense(3, activation="softmax"))
|
||||
|
||||
return model
|
||||
|
||||
|
||||
def load_data():
|
||||
iris = load_iris()
|
||||
x = iris.data
|
||||
@@ -34,18 +35,21 @@ def load_data():
|
||||
|
||||
y = keras.utils.to_categorical(y, 3)
|
||||
|
||||
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, shuffle=True, stratify=y)
|
||||
x_train, x_test, y_train, y_test = train_test_split(
|
||||
x, y, test_size=0.2, shuffle=True, stratify=y
|
||||
)
|
||||
|
||||
return x_train, x_test, y_train, y_test
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
model = make_model()
|
||||
x_train, x_test, y_train, y_test = load_data()
|
||||
print(x_train.shape, y_train.shape)
|
||||
|
||||
loss = ['categorical_crossentropy', 'accuracy','mse']
|
||||
metrics = ['accuracy']
|
||||
|
||||
model.compile(optimizer='sgd', loss=loss[0], metrics=metrics[0])
|
||||
loss = ["categorical_crossentropy", "accuracy", "mse"]
|
||||
metrics = ["accuracy"]
|
||||
|
||||
model.compile(optimizer="sgd", loss=loss[0], metrics=metrics[0])
|
||||
model.fit(x_train, y_train, epochs=200, batch_size=32, validation_split=0.2)
|
||||
model.evaluate(x_test, y_test, batch_size=32)
|
||||
model.evaluate(x_test, y_test, batch_size=32)
|
||||
|
||||
Reference in New Issue
Block a user