Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS725_Project
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Smit Gangurde
CS725_Project
Commits
69c081de
Commit
69c081de
authored
Dec 07, 2020
by
Khyati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added code
parent
843f29b2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
286 additions
and
0 deletions
+286
-0
Notebooks/RESNET152/indiandanceprediction-usingmonk.py
Notebooks/RESNET152/indiandanceprediction-usingmonk.py
+286
-0
No files found.
Notebooks/RESNET152/indiandanceprediction-usingmonk.py
0 → 100644
View file @
69c081de
#!/usr/bin/env python
# coding: utf-8
# In[1]:
pip
install
tornado
--
upgrade
--
use
-
feature
=
2020
-
resolver
# In[2]:
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]:
pip
install
bokeh
# In[4]:
pip
install
monk
--
upgrade
# In[5]:
pip
install
-
U
monk
-
kaggle
# In[6]:
import
numpy
as
np
# linear algebra
import
pandas
as
pd
# data processing, CSV file I/O (e.g. pd.read_csv)
import
matplotlib.pyplot
as
plt
from
PIL
import
Image
,
ImageDraw
import
os
import
sys
# In[7]:
sys
.
path
.
append
(
"/kaggle/working/monk_v1/monk/"
);
from
gluon_prototype
import
prototype
# In[8]:
gtf
=
prototype
(
verbose
=
1
);
gtf
.
Prototype
(
"Dance_Form"
,
"Indian_Classical_Dance_Form_Prediction"
);
# In[10]:
import
csv
# In[11]:
#to read the entries from train.csv
data
=
[]
with
open
(
'../input/dform-gold/dataset1/train.csv'
,
'r'
,)
as
file
:
reader
=
csv
.
reader
(
file
,
delimiter
=
','
)
i
=
0
for
row
in
reader
:
if
i
==
0
:
i
=
i
+
1
continue
data
.
append
(
row
);
print
(
data
)
# In[12]:
#used for cross validation, k : #iterations, div : #images in a division
k
=
4
div
=
len
(
data
)
/
k
# In[15]:
#to shuffle data and get a set which classifies all 8 classes
print
(
"division:"
,
div
)
#shuffling data
import
pandas
as
pd
flag
=
False
while
(
not
flag
):
flag
=
True
pdata
=
pd
.
DataFrame
(
data
)
pdata
=
pdata
.
sample
(
frac
=
1
)
data
=
pdata
.
values
.
tolist
()
for
i
in
range
(
k
):
train
=
(
data
[
0
:(
i
*
int
(
div
))])
test
=
data
[
i
*
int
(
div
)
:
(
i
+
1
)
*
int
(
div
)
]
for
x
in
data
[(
i
+
1
)
*
int
(
div
)
:
]:
train
.
append
(
x
)
if
(
len
(
pd
.
DataFrame
(
train
)
.
groupby
(
1
)
.
count
()[
0
])
<
8
or
len
(
pd
.
DataFrame
(
test
)
.
groupby
(
1
)
.
count
()[
0
])
<
8
):
flag
=
False
break
print
(
data
)
# In[18]:
#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
'''
accuracy
=
0
;
for
i
in
range
(
k
):
train
=
(
data
[
0
:(
i
*
int
(
div
))])
test
=
data
[
i
*
int
(
div
)
:
(
i
+
1
)
*
int
(
div
)
]
for
x
in
data
[(
i
+
1
)
*
int
(
div
)
:
]:
train
.
append
(
x
)
print
(
len
(
pd
.
DataFrame
(
train
)
.
groupby
(
1
)
.
count
()[
0
]))
print
(
pd
.
DataFrame
(
train
)
.
groupby
(
1
)
.
count
())
print
(
len
(
pd
.
DataFrame
(
test
)
.
groupby
(
1
)
.
count
()[
0
]))
print
(
pd
.
DataFrame
(
test
)
.
groupby
(
1
)
.
count
())
a
=
pd
.
DataFrame
(
train
,
columns
=
[
'Image'
,
'target'
]);
a
.
to_csv
(
"train_slot.csv"
,
index
=
False
);
a
=
pd
.
DataFrame
(
test
,
columns
=
[
'Image'
,
'target'
]);
a
.
to_csv
(
"test_slot.csv"
,
index
=
False
);
gtf
=
prototype
(
verbose
=
1
);
gtf
.
Prototype
(
"Dance_Form"
,
"resnet152_V1"
);
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
.
Reload
()
gtf
.
Train
();
combined
=
[];
predictions_dict
=
{};
j
=
0
with
open
(
'test_slot.csv'
,
'r'
,)
as
file
:
reader
=
csv
.
reader
(
file
,
delimiter
=
','
)
for
row
in
reader
:
if
(
j
==
0
):
j
=
j
+
1
continue
img_name
=
"../input/dform-gold/dataset1/train/"
+
row
[
0
];
predictions
=
gtf
.
Infer
(
img_name
=
img_name
);
id_
=
row
[
0
]
label
=
predictions
[
"predicted_class"
];
combined
.
append
([
id_
,
label
]);
predictions_dict
[
id_
]
=
label
;
print
(
predictions_dict
)
print
(
"predictions
\n\n\n\n\n
"
)
print
(
combined
)
gtf
.
Summary
()
gtf
.
EDA
(
show_img
=
True
,
save_img
=
True
);
# print(gtf.EDA(show_img=True, save_img=True))
import
csv
import
numpy
as
np
confusion_mat
=
{
'bharatanatyam'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'kathak'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'kathakali'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'kuchipudi'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'manipuri'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'mohiniyattam'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'odissi'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'sattriya'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
}
}
correct
=
0
with
open
(
'test_slot.csv'
,
'r'
,)
as
file
:
reader
=
csv
.
reader
(
file
,
delimiter
=
','
)
j
=
0
for
gold_label
in
reader
:
if
j
==
0
:
j
=
j
+
1
continue
confusion_mat
[
gold_label
[
1
]][
predictions_dict
[
gold_label
[
0
]]]
=
confusion_mat
[
gold_label
[
1
]][
predictions_dict
[
gold_label
[
0
]]]
+
1
if
(
gold_label
[
1
]
==
predictions_dict
[
gold_label
[
0
]]):
correct
=
correct
+
1
accuracy_of_iter
=
correct
/
div
print
(
"correct"
,
correct
,
"#images"
,
div
)
print
(
"accuracy for"
,
i
,
"th iteration:"
,
accuracy_of_iter
)
accuracy
=
accuracy
+
accuracy_of_iter
print
(
confusion_mat
)
print
(
"Overall accuracy:"
,
accuracy
/
k
)
# In[19]:
'''
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
},
'kathak'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'kathakali'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'kuchipudi'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'manipuri'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'mohiniyattam'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'odissi'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
},
'sattriya'
:{
'bharatanatyam'
:
0
,
'kathak'
:
0
,
'kathakali'
:
0
,
'kuchipudi'
:
0
,
'manipuri'
:
0
,
'mohiniyattam'
:
0
,
'odissi'
:
0
,
'sattriya'
:
0
}
}
j
=
0
combined
=
[]
correct
=
0
with
open
(
'../input/dform-gold/dataset1/gold_labels.csv'
,
'r'
,)
as
file
:
reader
=
csv
.
reader
(
file
,
delimiter
=
','
)
for
gold_label
in
reader
:
if
(
j
==
0
):
j
=
j
+
1
continue
img_name
=
"../input/dform-gold/dataset1/test/"
+
gold_label
[
0
];
predictions
=
gtf
.
Infer
(
img_name
=
img_name
);
id_
=
gold_label
[
0
]
label
=
predictions
[
"predicted_class"
];
combined
.
append
([
id_
,
label
]);
confusion_mat
[
gold_label
[
1
]][
label
]
=
confusion_mat
[
gold_label
[
1
]][
label
]
+
1
if
(
gold_label
[
1
]
==
label
):
correct
=
correct
+
1
# predictions_dict[id_] = label;
print
(
"#correct labels "
,
correct
,
'out of'
,
len
(
combined
))
print
(
"test accuracy :"
,
correct
/
len
(
combined
))
conf_mat
=
pd
.
DataFrame
(
confusion_mat
)
print
(
conf_mat
)
# In[ ]:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment