<jupyter_start><jupyter_text>test init<jupyter_code>tf.reset_default_graph()
n_mfcc = 16
n_frame = 16
n_classes = 7
n_channels = 1

kernel_size = 3
stride = 1
pad = "SAME"

learning_rate = 0.0002
X = tf.placeholder(tf.float32, shape=[None,n_mfcc*n_frame*n_channels])
#X = tf.reshape(X, [-1, n_mfcc, n_frame, n_channels]) #fully connected에는 리셰입 안해도 된다 
Y = tf.placeholder(tf.float32, shape=[None,n_classes])

keep_prob = tf.placeholder(tf.float32)

#dense2 = tf.layers.dense(inputs=flat, units=625, activation=tf.nn.relu)
#dropout2 = tf.layers.dropout(inputs=dense2, rate=0.5, training=True)
dense1 = tf.layers.dense(inputs=X, units=256, activation=tf.nn.relu)
dropout1 = tf.nn.dropout(dense1, keep_prob=keep_prob)
dense2 = tf.layers.dense(inputs=dropout1, units=256, activation=tf.nn.relu)
dropout2 = tf.nn.dropout(dense2, keep_prob=keep_prob)
dense3 = tf.layers.dense(inputs=dropout2, units=512, activation=tf.nn.relu)
dropout3 = tf.nn.dropout(dense3, keep_prob=keep_prob)
#이거 지워보고 돌려보고 
dense4 = tf.layers.dense(inputs=dropout3, units=512, activation=tf.nn.relu)
dropout4 = tf.nn.dropout(dense4, keep_prob=keep_prob)
dense5 = tf.layers.dense(inputs=dropout4, units=256, activation=tf.nn.relu)
dropout5 = tf.nn.dropout(dense5, keep_prob=keep_prob)

logits= tf.layers.dense(inputs=dropout5, units=7)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=logits, labels=Y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
# Model Save
sess=tf.Session()
saver = tf.train.Saver()
saver.restore(sess, '../../model/DNN/7_dense_model')
# Prediction
y_test = sess.run(tf.nn.softmax(logits), feed_dict={X: X_test, keep_prob:1})
y_pred = sess.run(tf.argmax(logits,1),feed_dict={X: X_test , keep_prob:1}) 
y_true = sess.run(tf.argmax(y_encoded,1))
print(type(y_test))
def conversion(input):
    switcher ={
        0: 1,
        1: 10,
        2: 20,
        3: 30,
        4: 40,
        5: 50,
        6: 100
    }
    return switcher.get(input)
import pandas as pd
pd.options.display.max_rows = 4000
#print(pd.DataFrame(y_test))
resultX = []
resultY = []
predX = []
meanX = []
meanY = []
out_mean = []

# 1m
sum = 0
out_sum = 0
for i in range(0,24):
    cal = round(y_test[i][0]*1+y_test[i][1]*10+y_test[i][2]*20+y_test[i][3]*30+y_test[i][4]*40+y_test[i][5]*50+y_test[i][6]*100,2)
    sum += cal
    resultX.append(cal)
    resultY.append(1)
    
    out = int(conversion(y_pred[i]))
    predX.append(out)
    out_sum += out

meanX.append(sum/24)
meanY.append(1)
out_mean.append(out_sum/24)
sum = 0
out_sum = 0

# 10m
for i in range(34,58):
    cal = round(y_test[i][0]*1+y_test[i][1]*10+y_test[i][2]*20+y_test[i][3]*30+y_test[i][4]*40+y_test[i][5]*50+y_test[i][6]*100,2)
    sum += cal
    resultX.append(cal)
    resultY.append(10)
    
    out = int(conversion(y_pred[i]))
    predX.append(out)
    out_sum += out

meanX.append(sum/24)
meanY.append(10)
out_mean.append(out_sum/24)
sum = 0
out_sum = 0

# 20m
for i in range(58,82):
    cal = round(y_test[i][0]*1+y_test[i][1]*10+y_test[i][2]*20+y_test[i][3]*30+y_test[i][4]*40+y_test[i][5]*50+y_test[i][6]*100,2)
    sum += cal
    resultX.append(cal)
    resultY.append(20)
    
    out = int(conversion(y_pred[i]))
    predX.append(out)
    out_sum += out

meanX.append(sum/24)
meanY.append(20)
out_mean.append(out_sum/24)
sum = 0
out_sum = 0

# 30m
for i in range(82,106):
    cal = round(y_test[i][0]*1+y_test[i][1]*10+y_test[i][2]*20+y_test[i][3]*30+y_test[i][4]*40+y_test[i][5]*50+y_test[i][6]*100,2)
    sum += cal
    resultX.append(cal)
    resultY.append(30)
    
    out = int(conversion(y_pred[i]))
    predX.append(out)
    out_sum += out

meanX.append(sum/24)
meanY.append(30)
out_mean.append(out_sum/24)
sum = 0
out_sum = 0

# 40m
for i in range(108,132):
    cal = round(y_test[i][0]*1+y_test[i][1]*10+y_test[i][2]*20+y_test[i][3]*30+y_test[i][4]*40+y_test[i][5]*50+y_test[i][6]*100,2)
    sum += cal
    resultX.append(cal)
    resultY.append(40)
    
    out = int(conversion(y_pred[i]))
    predX.append(out)
    out_sum += out

meanX.append(sum/24)
meanY.append(40)
out_mean.append(out_sum/24)
sum = 0
out_sum = 0

# 50m
for i in range(142,166):
    cal = round(y_test[i][0]*1+y_test[i][1]*10+y_test[i][2]*20+y_test[i][3]*30+y_test[i][4]*40+y_test[i][5]*50+y_test[i][6]*100,2)
    sum += cal
    resultX.append(cal)
    resultY.append(50)
    
    out = int(conversion(y_pred[i]))
    predX.append(out)
    out_sum += out

meanX.append(sum/24)
meanY.append(50)
out_mean.append(out_sum/24)
for i in range(0, len(predX)):
    if i%24 == 23:
        print(predX[i])
    else:
        print(predX[i],' ' ,end='')

import matplotlib.pyplot as plt
%matplotlib inline

fig= plt.figure(figsize=(5,10))
axes= fig.add_subplot(111)

plt.ylim(0, 100)
plt.xlim(0,50)
axes.plot(resultY, resultX,'x')
plt.xlabel('Actual Distance (m)')
plt.ylabel('Calculated Distance (m)')
axes.plot(meanY, meanX)

axes.set_yticks([0,10,20,30,40,50,60,70,80,90,100])

plt.savefig('graph7-04percentage.png',dpi=900)
import matplotlib.pyplot as plt
%matplotlib inline

fig= plt.figure(figsize=(5,10))
axes= fig.add_subplot(111)

plt.ylim(0, 100)
plt.xlim(0,50)
plt.xlabel('Actual Distance (m)')
plt.ylabel('Calculated Distance (m)')
axes.plot(resultY,predX,'x')
axes.plot(meanY, out_mean)

axes.set_yticks([0,10,20,30,40,50,60,70,80,90,100])

plt.savefig('graph7-04output.png',dpi=900)
sec1x = [1,1,1,1,1,10,20,10,10,10,20,20,20,20,20,30,30,30,30,30,40,40,40,40,40,50,50,20,50,50]
sec1y = [1,1,1,1,1,10,10,10,10,10,20,20,20,20,20,30,30,30,30,30,40,40,40,40,40,50,50,50,50,50]
sec1meanX = [1,12,20,30,40,44]
sec1meanY = [1,10,20,30,40,50]
sec2x = [1,1,1,20,10,10,20,20,20,30,30,30,40,40,40,50,20,50]
sec2y = [1,1,1,10,10,10,20,20,20,30,30,30,40,40,40,50,50,50]
sec2meanX = [1,13.33,20,30,40,46.67]
sec2meanY = [1,10,20,30,40,50]
import matplotlib.pyplot as plt
%matplotlib inline

fig= plt.figure(figsize=(5,10))
axes= fig.add_subplot(111)

plt.ylim(0, 100)
plt.xlim(0,50)
plt.xlabel('Actual Distance (m)')
plt.ylabel('Calculated Distance (m)')
axes.plot(sec1y, sec1x , 'x')
axes.plot(sec1meanY, sec1meanX)

axes.set_yticks([0,10,20,30,40,50,60,70,80,90,100])

plt.savefig('graph7-1output.png',dpi=900)
import matplotlib.pyplot as plt
%matplotlib inline

fig= plt.figure(figsize=(5,10))
axes= fig.add_subplot(111)

plt.ylim(0, 100)
plt.xlim(0,50)
plt.xlabel('Actual Distance (m)')
plt.ylabel('Calculated Distance (m)')
axes.plot(sec2y, sec2x , 'x')
axes.plot(sec2meanY, sec2meanX)

axes.set_yticks([0,10,20,30,40,50,60,70,80,90,100])

plt.savefig('graph7-2output.png',dpi=900)
print('mean : ', meanX)
print('out_mean: ', out_mean)
print('1sec_out_mean', sec1meanX)
print('2sec_out_mean', sec2meanX)
# Print Result

from sklearn.metrics import precision_recall_fscore_support
y_true = y_true
y_pred = y_pred

p,r,f,s = precision_recall_fscore_support(y_true, y_pred, average='micro')
print("F-Score:", round(f,2))
from sklearn.metrics import accuracy_score
print("Accuracy: ", accuracy_score(y_true, y_pred))


#fig = plt.figure(figsize=(15,9))
#ax = fig.add_subplot(1,1,1)
#ax.plot(np.linspace(0,len(y_pred), len(y_pred)),y_true, 'x')


fig = plt.figure(figsize=(15,9))
ax = fig.add_subplot(1,1,1)
ax.plot(np.linspace(0,len(y_pred), len(y_pred)),y_pred, 'x')

from sklearn.metrics import classification_report
print(classification_report(y_true, y_pred))
from sklearn.metrics import confusion_matrix
print(confusion_matrix(y_true, y_pred))<jupyter_output>F-Score: 0.9
Accuracy:  0.905
              precision    recall  f1-score   support

           0       1.00      1.00      1.00        24
           1       1.00      0.71      0.83        34
           2       0.56      1.00      0.72        24
           3       1.00      1.00      1.00        26
           4       1.00      1.00      1.00        34
           5       1.00      0.82      0.90        34
           6       1.00      0.88      0.93        24

   micro avg       0.91      0.91      0.91       200
   macro avg       0.94      0.91      0.91       200
weighted avg       0.95      0.91      0.91       200

[[24  0  0  0  0  0  0]
 [ 0 24 10  0  0  0  0]
 [ 0  0 24  0  0  0  0]
 [ 0  0  0 26  0  0  0]
 [ 0  0  0  0 34  0  0]
 [ 0  0  6  0  0 28  0]
 [ 0  0  3  0  0  0 21]]
{'fraction_non_alphanumeric': 0.17717827196500183, 'fraction_numerical': 0.11350103293231255, 'mean_word_length': 4.039804041641151, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '106493', 'license': 'MIT', 'n_tokens_mistral': 4200, 'n_tokens_neox': 3736, 'n_words': 576, 'path': 'notebook/DNN/Dense-Test-7.ipynb', 'repo_name': 'gunhoo/Drone-Tracking', 'size': '8229'}