script file added

parent 3f6757f2
#!/usr/bin/env python
# coding: utf-8
# In[1]:
# In[16]:
pip install tornado --upgrade --use-feature=2020-resolver
# In[2]:
# In[17]:
get_ipython().system('git clone https://github.com/Tessellate-Imaging/monk_v1.git')
get_ipython().system('cd monk_v1/installation/Misc && pip install -r requirements_kaggle.txt --use-feature=2020-resolver')
# In[3]:
# In[ ]:
pip install bokeh
pip install bokeh --use-feature=2020-resolver
# In[4]:
# In[ ]:
pip install monk --upgrade
pip install monk --upgrade --use-feature=2020-resolver
# In[5]:
# In[ ]:
pip install -U monk-kaggle
pip install -U monk-kaggle --use-feature=2020-resolver
# In[6]:
# In[18]:
import numpy as np # linear algebra
......@@ -43,30 +43,29 @@ import os
import sys
# In[7]:
# In[19]:
sys.path.append("/kaggle/working/monk_v1/monk/");
from gluon_prototype import prototype
# In[8]:
# In[20]:
gtf = prototype(verbose=1);
gtf.Prototype("Dance_Form", "Indian_Classical_Dance_Form_Prediction");
# In[10]:
# In[21]:
import csv
# In[11]:
# In[22]:
#to read the entries from train.csv
data = []
with open('../input/dform-gold/dataset1/train.csv', 'r',) as file:
reader = csv.reader(file, delimiter = ',')
......@@ -79,19 +78,18 @@ with open('../input/dform-gold/dataset1/train.csv', 'r',) as file:
print(data)
# In[12]:
# In[23]:
#used for cross validation, k : #iterations, div : #images in a division
k = 4
div = len(data) / k
#7 * 13* 2 * 2
# In[15]:
# In[24]:
#to shuffle data and get a set which classifies all 8 classes
print("division:",div)
print(div)
#shuffling data
......@@ -116,6 +114,8 @@ while (not flag):
test = data[ i * int(div) : (i + 1) * int(div) ]
for x in data[(i+1) * int(div) : ]:
train.append(x)
print(i, "train count",len(pd.DataFrame(train).groupby(1).count()[0]))
print(i, "test count",len(pd.DataFrame(train).groupby(1).count()[0]))
if(len(pd.DataFrame(train).groupby(1).count()[0]) < 8 or len(pd.DataFrame(test).groupby(1).count()[0]) < 8):
flag = False
break
......@@ -124,28 +124,10 @@ while (not flag):
print(data)
# In[18]:
# In[25]:
#performed cross validation and created confusion matrix for cross validation
'''
Model : resnet152_v1
#epochs:20
optimizer:adam
batch_size:7
learning_rate:0.005
data shuffle : true
'''
'''
Result:
Epochs for every iteration:
test accuracy, train accuracy, test loss, train loss
Summary of the model
Best accuracy after every iteration
Final average accuracy taken from the #iterations
'''
print(data)
accuracy = 0;
for i in range(k):
......@@ -163,20 +145,24 @@ for i in range(k):
a.to_csv("test_slot.csv", index=False);
gtf = prototype(verbose=1);
gtf.Prototype("Dance_Form", "resnet152_V1");
gtf.Prototype("Dance_Form", "Model");
gtf.Default(dataset_path=["../input/dform-gold/dataset1/train", "../input/dform-gold/dataset1/train"], path_to_csv=["train_slot.csv","test_slot.csv"], model_name="resnet152_v1", freeze_base_network=True, num_epochs=20);
gtf.update_shuffle_data(True);
gtf.optimizer_adam(0.001);
gtf.update_batch_size(7);
gtf.update_learning_rate(0.005);
gtf.Default(dataset_path=["../input/dform-gold/dataset1/train", "../input/dform-gold/dataset1/train"], path_to_csv=["train_slot.csv","test_slot.csv"], model_name="resnet152_v1", freeze_base_network=False, num_epochs=10);
#gtf.update_trainval_split(0.99);
# gtf.update_shuffle_data(True);
# gtf.optimizer_adam(0.001);
# gtf.update_batch_size(7);
# gtf.update_learning_rate(0.005);
gtf.Reload()
gtf.Train();
# gtf.Dataset_Params(dataset_path="../input/dform-gold/dataset1/test", path_to_csv="../input/dform-gold/dataset1/gold_labels.csv");
#list_test=os.listdir("../input/dform-gold/dataset1/test/");
#from tqdm.notebook import tqdm
combined = [];
predictions_dict = {};
j = 0
......@@ -197,7 +183,7 @@ for i in range(k):
print(predictions_dict)
print("predictions\n\n\n\n\n")
print(combined)
gtf.Summary()
# gtf.Summary()
gtf.EDA(show_img=True, save_img=True);
# print(gtf.EDA(show_img=True, save_img=True))
import csv
......@@ -230,19 +216,14 @@ for i in range(k):
print("correct",correct,"#images",div)
print("accuracy for", i, "th iteration:", accuracy_of_iter)
accuracy = accuracy + accuracy_of_iter
print(confusion_mat)
# print(confusion_mat)
print("Overall accuracy:", accuracy / k)
# In[19]:
# In[26]:
'''
checking the model on test by comparing the gold labels of the test data and the prediction of model
Creating confusion Matrix(real classes vs predicted ones)
Calculating Final test accuracy
'''
confusion_mat = {
'bharatanatyam':{'bharatanatyam':0,'kathak':0,'kathakali':0,'kuchipudi':0,'manipuri':0,'mohiniyattam':0,'odissi':0,'sattriya':0},
......@@ -282,5 +263,5 @@ print(conf_mat)
# In[ ]:
gtf.List_Models()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment