JH721 SW자율차 [DeepLearning, CNN] //9주차-5
DNN
from numpy import array, newaxis, random
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM
x = array([[i*j for i in range(1,10)] for j in range(2,10)])
y = array([i+2 for i in range(8)])
print(x.shape)
print(x)
print(y.shape)
print(y)
x = x[..., newaxis]
print(y.shape)
model = Sequential()
model.add(LSTM(20, activation = 'relu', input_shape=(9,1))) # LSTM : numOfCell -> 4*n*(n+2)
model.add(Dense(5))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
from tensorflow.keras.callbacks import EarlyStopping
early_stopping = EarlyStopping(monitor='loss', patience=3)
model.summary()
model.fit(x,y, epochs=1000, batch_size=1, verbose=2, callbacks=[early_stopping])
x_input = array([(i+1)*21 for i in range(9)]).reshape(1,9,1)
print(x_input)
y_hat = model.predict(x_input)
print(y_hat)
we ar looking for memory control, we dont need to know how to work
virtual
download virtualenv : sudo -H pip3 install virtualenv
virtualenv (tf1: dirctory name)
source tf1/bin/activate
character detect
import tensorflow as tf
import numpy as np
unique = 'helo'
y_data = [1,2,2,3]
x_data = np.array([[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,1,0]], dtype='f')
cells = tf.nn.rnn_cell.BasicRNNCell(4)
state = tf.zeros([1, cells.state_size])
x_data = tf.split(x_data, 4)
outputs, state = tf.nn.static_rnn(cells, x_data, state)
logits = tf .reshape(outputs, [-1, 4])
targets = tf.reshape(y_data, [-1])
weights = tf.ones([4])
loss = tf.contrib.legacy_seq2seq.sequence_loss_by_example([logits], [targets], [weights])
cost = tf.reduce_sum(loss)
train_op = tf.train.RMSPropOptimizer(0.01,0.9).minimize(cost)
with tf.Session() as sess:
tf.global_variables_initializer().run()
for i in range(100):
sess.run(train_op)
r0,r1,r2,r3 = sess.run(tf.argmax(logits, 1))
print(r0,r1,r2,r3, ':', unique[r0], unique[r1], unique[r2], unique[r3])
Author And Source
이 문제에 관하여(JH721 SW자율차 [DeepLearning, CNN] //9주차-5), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@yxxy212/JH721-SW자율차-DeepLearning-CNN-9주차-5저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)