Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
aed25f1
Delete 1.pdf
THEFASHIONGEEK Dec 3, 2019
4ce1954
Update Write_Into_TFRecords.py
THEFASHIONGEEK Dec 3, 2019
122006f
Delete small_train_sample.csv
THEFASHIONGEEK Dec 3, 2019
59e3efc
Add files via upload
THEFASHIONGEEK Dec 3, 2019
5fe6cb1
Update Write_Into_TFRecords.py
THEFASHIONGEEK Dec 3, 2019
98690bf
Update feat_extraction_from_wav.py
THEFASHIONGEEK Dec 3, 2019
8697471
Delete annotation_training.pkl
THEFASHIONGEEK Dec 3, 2019
33992ea
Delete annotation_validation.pkl
THEFASHIONGEEK Dec 3, 2019
61c75fc
Update README.md
THEFASHIONGEEK Dec 3, 2019
396fa3b
Update dan.py
THEFASHIONGEEK Dec 5, 2019
8327883
Update dan.py
THEFASHIONGEEK Dec 5, 2019
c562b51
Update README.md
THEFASHIONGEEK Dec 7, 2019
8e71638
Update README.md
THEFASHIONGEEK Dec 7, 2019
725bd7d
Add files via upload
THEFASHIONGEEK Dec 9, 2019
33b67ed
Update README.md
THEFASHIONGEEK Dec 9, 2019
f1a60fe
Update Video_to_Image.py
THEFASHIONGEEK Dec 9, 2019
5225139
Update README.md
THEFASHIONGEEK Dec 9, 2019
9f627a5
Delete dan.pyc
THEFASHIONGEEK Dec 9, 2019
67a2ebe
Delete remtime.pyc
THEFASHIONGEEK Dec 9, 2019
faa805e
Update train.py
THEFASHIONGEEK Dec 11, 2019
6532ae5
Update dan.py
THEFASHIONGEEK Dec 11, 2019
62c2996
Update Video_to_Image.py
THEFASHIONGEEK Dec 11, 2019
76d9c08
Update Write_Into_TFRecords.py
THEFASHIONGEEK Dec 11, 2019
4576537
Update feat_extraction_from_wav.py
THEFASHIONGEEK Dec 11, 2019
054b1c6
Update test.py
THEFASHIONGEEK Dec 11, 2019
b596dfd
Update vid_to_wav.py
THEFASHIONGEEK Dec 11, 2019
9dac652
Add files via upload
THEFASHIONGEEK Dec 12, 2019
66dc9d7
Update demo.py
THEFASHIONGEEK Dec 12, 2019
157b444
Add files via upload
THEFASHIONGEEK Dec 12, 2019
3f8e65c
Update dan.py
THEFASHIONGEEK Dec 12, 2019
d726f0b
Update dan_plus.py
THEFASHIONGEEK Dec 12, 2019
1c096e2
Update requirements.txt
THEFASHIONGEEK Dec 12, 2019
563f40e
Update dan_plus.py
THEFASHIONGEEK Dec 13, 2019
2c2930b
Update requirements.txt
THEFASHIONGEEK Dec 13, 2019
7bca545
Add files via upload
THEFASHIONGEEK Dec 13, 2019
bbc72f3
Update README.md
THEFASHIONGEEK Dec 13, 2019
0eb77ab
Update README.md
THEFASHIONGEEK Dec 13, 2019
e45ceb1
Delete modelImg.png
THEFASHIONGEEK Dec 13, 2019
0d321b1
Update LICENSE
THEFASHIONGEEK Jan 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed 1.pdf
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file added Images/Dan_model.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 THEFASHIONGEEK
Copyright (c) 2019 AKULA HEMANTH KUMAR

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ As is known, the first impression made is highly important in many contexts, suc

The model used is called `Descriptor Aggregation Network` called DAN in short.

![Model Archi](modelImg.png)
![Model Archi](Images/Dan_model.PNG)

What distinguishes DAN from the traditional CNN is: the fully connected layers are discarded, and replaced by both average- and max-pooling following the last convolutional layers (Pool5). Meanwhile, each pooling operation is followed by the standard L2-normalization. After that, the obtained two 512-d feature vectors are concatenated as the final image representation. Thus, in DAN, the deep descriptors of the last convolutional layers are aggregated as a single visual feature. Finally, a regression (fc+sigmoid) layer is added for end-to-end training.

Expand All @@ -28,7 +28,7 @@ These instructions will get you a copy of the project up and running on your loc
### Prerequisites

* [Python3](https://www.python.org/downloads/release/python-373/) - Python version 3.7.3
* [Numpy](http://www.numpy.org/) - Multidimensioanl Mathematical Computing
* [Numpy](http://www.numpy.org/) - Multidimensional Mathematical Computing
* [Tensorflow 1.14.0](https://www.tensorflow.org/) - Deep Learning python module
* [Pandas](https://pandas.pydata.org/) - Loading csv files
* [Cha-Learn Dataset](http://chalearnlap.cvc.uab.es/dataset/24/description/) - Dataset for this problem
Expand All @@ -37,6 +37,7 @@ These instructions will get you a copy of the project up and running on your loc
* [OpenCV 3.4.1](https://breakthrough.github.io/Installing-OpenCV/) library used for Image Processing
* [ffmpeg](https://ffmpeg.zeranoe.com/builds/ ) software suite of libraries and programs for handling video, audio, and other multimedia
files and streams
* [python_speech_features](https://pypi.org/project/python_speech_features/) This library provides common speech features for ASR including MFCCs and filterbank energies

### Installing

Expand All @@ -46,10 +47,15 @@ Clone the repository
git clone https://github.com/THEFASHIONGEEK/First-Impression.git
```

Downlad the training dataset and extract it into a new /data directory with all 75 training zip files and 25 validation zip files as it is, we will extract them through the script.
Download the training dataset and extract it into a new /data directory with all 75 training zip files and 25 validation zip files as it is, we will extract them through the script.

[Download](http://www.vlfeat.org/matconvnet/models/vgg-face.mat) Pretrained Vgg-face model and move it to the root directory

Run the requirements.txt

```
pip install -r requirements.txt
```
Run the Video_to_Image.py file to scrape the images from the videos and save it to a new ImageData directory

```
Expand All @@ -66,6 +72,11 @@ If succesfully completed then run the Write_Into_TFRecords.py file to form a dat
```
python Write_Into_TFRecords.py
```
Run the feat_extraction_from_wav.py file to form a data pipeline by saving the all the train audio into train_audio_full.tfrecords file , all the validation images into val_audio_full.tfrecords to load it later during training

```
python feat_extraction_from_wav.py
```

Start the training by running the following command

Expand All @@ -78,3 +89,5 @@ python train.py

* [paper](https://cs.nju.edu.cn/wujx/paper/eccvw16_APA.pdf) - Implemented paper
* [TfRecord Data Pipeline](http://machinelearninguru.com/deep_learning/data_preparation/tfrecord/tfrecord.html#read) - Used to make data pipeline
* [VGG16 in TensorFlow](https://www.cs.toronto.edu/~frossard/post/vgg16/) - Used in DAN
* [Author's code](https://github.com/tzzcl/ChaLearn-APA-Code#2-extract-audio-feature-from-video)
124 changes: 72 additions & 52 deletions Video_to_Image.py
Original file line number Diff line number Diff line change
@@ -1,107 +1,127 @@
'''
"""
Extract all the 6 training zipped files and 2 validation zipped files into data folder and then run this script
'''
import cv2
import numpy as np
"""
import os
import zipfile

## Runnin a loop throught all the zipped training file to extract all video and then extract 100 frames from each.
for i in range(1,76):
if i<10:
zipfilename = 'training80_0'+str(i)+'.zip'
import numpy as np

import cv2

# Runnin a loop throught all the zipped training file to extract all video and then extract 100 frames from each.

### Training data ###
for i in range(1, 76):
if i < 10:
zipfilename = "training80_0" + str(i) + ".zip"
else:
zipfilename = 'training80_'+str(i)+'.zip'
zipfilename = "training80_" + str(i) + ".zip"
## Accessing the zipfile i
archive = zipfile.ZipFile('data/'+zipfilename, 'r')
zipfilename = zipfilename.split('.zip')[0]
archive = zipfile.ZipFile("data/" + zipfilename, "r")
zipfilename = zipfilename.split(".zip")[0]

##Extracting all videos in it and saving it all to the new folder with same name as zipped one
archive.extractall('unzippedData/'+zipfilename)
archive.extractall("unzippedData/" + zipfilename)

## Running a loop over all the videos in the zipped file and extracting 100 frames from each
for file_name in archive.namelist():
cap = cv2.VideoCapture('unzippedData/'+zipfilename+'/'+file_name)
cap = cv2.VideoCapture("unzippedData/" + zipfilename + "/" + file_name)

file_name=(file_name.split('.mp4'))[0]
file_name = (file_name.split(".mp4"))[0]
## Creating folder to save all the 100 frames from the video
try:
if not os.path.exists('ImageData/trainingData/'+file_name):
os.makedirs('ImageData/trainingData/'+file_name)
if not os.path.exists("ImageData/trainingData/" + file_name):
os.makedirs("ImageData/trainingData/" + file_name)
except OSError:
print ('Error: Creating directory of data')
print("Error: Creating directory of data")

## Setting the frame limit to 100
cap.set(cv2.CAP_PROP_FRAME_COUNT, 101)
length=101
count=0
length = 101
count = 0
## Running a loop to each frame and saving it in the created folder
while(cap.isOpened()):
count+=1
if length==count:
while cap.isOpened():
count += 1
if length == count:
break
ret, frame = cap.read()
if frame is None:
continue

## Resizing it to 256*256 to save the disk space and fit into the model
frame = cv2.resize(frame,(256, 256), interpolation = cv2.INTER_CUBIC)
frame = cv2.resize(frame, (256, 256), interpolation=cv2.INTER_CUBIC)
# Saves image of the current frame in jpg file
name = 'ImageData/trainingData/'+str(file_name)+'/frame' + str(count) + '.jpg'
name = (
"ImageData/trainingData/"
+ str(file_name)
+ "/frame"
+ str(count)
+ ".jpg"
)
cv2.imwrite(name, frame)
if cv2.waitKey(1) & 0xFF == ord('q'):

if cv2.waitKey(1) & 0xFF == ord("q"):
break

## Print the file which is done
print (zipfilename, ':', file_name)
#
for i in range(1,26):
if i<10:
zipfilename = 'validation80_0'+str(i)+'.zip'
print(zipfilename, ":", file_name)
### Training data ###

### Validation data ###
for i in range(1, 26):
if i < 10:
zipfilename = "validation80_0" + str(i) + ".zip"
else:
zipfilename = 'validation80_'+str(i)+'.zip'
zipfilename = "validation80_" + str(i) + ".zip"
## Accessing the zipfile i
archive = zipfile.ZipFile('data/'+zipfilename, 'r')
zipfilename = zipfilename.split('.zip')[0]
archive = zipfile.ZipFile("data/" + zipfilename, "r")
zipfilename = zipfilename.split(".zip")[0]

##Extracting all videos in it and saving it all to the new folder with same name as zipped one
archive.extractall('unzippedData/'+zipfilename)
archive.extractall("unzippedData/" + zipfilename)

## Running a loop over all the videos in the zipped file and extracting 100 frames from each
for file_name in archive.namelist():
cap = cv2.VideoCapture('unzippedData/'+zipfilename+'/'+file_name)
cap = cv2.VideoCapture("unzippedData/" + zipfilename + "/" + file_name)

file_name=(file_name.split('.mp4'))[0]
file_name = (file_name.split(".mp4"))[0]
## Creating folder to save all the 100 frames from the video
try:
if not os.path.exists('ImageData/validationData/'+file_name):
os.makedirs('ImageData/validationData/'+file_name)
if not os.path.exists("ImageData/validationData/" + file_name):
os.makedirs("ImageData/validationData/" + file_name)
except OSError:
print ('Error: Creating directory of data')
print("Error: Creating directory of data")

## Setting the frame limit to 100
cap.set(cv2.CAP_PROP_FRAME_COUNT, 101)
length=101
count=0
length = 101
count = 0
## Running a loop to each frame and saving it in the created folder
while(cap.isOpened()):
count+=1
if length==count:
while cap.isOpened():
count += 1
if length == count:
break
ret, frame = cap.read()
if frame is None:
continue

## Resizing it to 256*256 to save the disk space and fit into the model
frame = cv2.resize(frame,(256, 256), interpolation = cv2.INTER_CUBIC)
frame = cv2.resize(frame, (256, 256), interpolation=cv2.INTER_CUBIC)
# Saves image of the current frame in jpg file
name = 'ImageData/validationData/'+str(file_name)+'/frame' + str(count) + '.jpg'
name = (
"ImageData/validationData/"
+ str(file_name)
+ "/frame"
+ str(count)
+ ".jpg"
)
cv2.imwrite(name, frame)
if cv2.waitKey(1) & 0xFF == ord('q'):

if cv2.waitKey(1) & 0xFF == ord("q"):
break

## Print the file which is done
print (zipfilename, ':', file_name)
print(zipfilename, ":", file_name)

### Validation data ###

Loading