-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8017af8
commit d5a94c4
Showing
21 changed files
with
1,294 additions
and
298 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Predicted_Videos/*.mp4 | ||
MOS.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
Data/Naturalness_Features/*.npy | ||
Data/VINE_Features/*/*.npy | ||
Data/SSA_Features/*/*.npy | ||
Data/Predicted_Videos | ||
Data/MOS.csv | ||
Runs/* | ||
Trained_Models/ |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: RM012_C3D2 | ||
channels: | ||
- conda-forge | ||
- defaults | ||
dependencies: | ||
- _libgcc_mutex=0.1=main | ||
- c-ares=1.17.1=h36c2ea0_0 | ||
- ca-certificates=2020.12.5=ha878542_0 | ||
- cached-property=1.5.1=py_0 | ||
- certifi=2020.12.5=py36h5fab9bb_1 | ||
- h5py=3.1.0=nompi_py36hc1bc4f5_100 | ||
- hdf5=1.10.6=nompi_h7c3c948_1111 | ||
- joblib=1.0.1=pyhd8ed1ab_0 | ||
- krb5=1.17.2=h926e7f8_0 | ||
- ld_impl_linux-64=2.33.1=h53a641e_7 | ||
- libblas=3.9.0=3_openblas | ||
- libcblas=3.9.0=3_openblas | ||
- libcurl=7.71.1=hcdd3856_8 | ||
- libedit=3.1.20191231=h14c3975_1 | ||
- libev=4.33=h516909a_1 | ||
- libffi=3.3=he6710b0_2 | ||
- libgcc-ng=9.1.0=hdf63c60_0 | ||
- libgfortran-ng=7.5.0=hae1eefd_17 | ||
- libgfortran4=7.5.0=hae1eefd_17 | ||
- liblapack=3.9.0=3_openblas | ||
- libnghttp2=1.41.0=h8cfc5f6_2 | ||
- libopenblas=0.3.12=pthreads_hb3c22a3_1 | ||
- libssh2=1.9.0=hab1572f_5 | ||
- libstdcxx-ng=9.1.0=hdf63c60_0 | ||
- ncurses=6.2=he6710b0_1 | ||
- numpy=1.19.4=py36h8732dcd_1 | ||
- openssl=1.1.1j=h27cfd23_0 | ||
- pandas=1.0.1=py36hb3f55d8_0 | ||
- pip=20.3.1=py36h06a4308_0 | ||
- python=3.6.12=hcff3b4d_2 | ||
- python-dateutil=2.8.1=py_0 | ||
- python_abi=3.6=1_cp36m | ||
- pytz=2021.1=pyhd8ed1ab_0 | ||
- readline=8.0=h7b6447c_0 | ||
- scikit-learn=0.23.2=py36hb6e6923_3 | ||
- scikit-video=1.1.11=pyh24bf2e0_0 | ||
- setuptools=51.0.0=py36h06a4308_2 | ||
- simplejson=3.17.2=py36h8c4c3a4_1 | ||
- six=1.15.0=pyh9f0ad1d_0 | ||
- sqlite=3.33.0=h62c20be_0 | ||
- threadpoolctl=2.1.0=pyh5ca1d4c_0 | ||
- tk=8.6.10=hbc83047_0 | ||
- tqdm=4.59.0=pyhd8ed1ab_0 | ||
- wheel=0.36.1=pyhd3eb1b0_0 | ||
- xz=5.2.5=h7b6447c_0 | ||
- zlib=1.2.11=h7b6447c_3 | ||
- pip: | ||
- cycler==0.10.0 | ||
- dask==2020.12.0 | ||
- decorator==4.4.2 | ||
- keras==0.3.3 | ||
- kiwisolver==1.3.1 | ||
- matplotlib==3.3.3 | ||
- networkx==2.5 | ||
- pillow==8.0.1 | ||
- pyparsing==2.4.7 | ||
- pyyaml==5.3.1 | ||
- scikit-image==0.12.3 | ||
- scipy==1.5.4 | ||
- theano==0.8.1 | ||
- toolz==0.11.1 | ||
prefix: /media/nagabhushan/Data02/SoftwareFiles/Anaconda/anaconda3/envs/RM012_C3D2 | ||
|
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Shree KRISHNAya Namaha | ||
# C3D Conv Net | ||
# https://gist.github.com/albertomontesg/d8b21a179c1e6cca0480ebdf292c34d2 | ||
# Author: Nagabhushan S N | ||
# Last Modified: 14/03/2021 | ||
|
||
import datetime | ||
import os | ||
import time | ||
import traceback | ||
|
||
from tqdm import tqdm | ||
|
||
os.environ['KERAS_BACKEND'] = 'theano' | ||
|
||
from pathlib import Path | ||
import numpy | ||
import skimage.transform | ||
import skvideo.io | ||
from keras import backend | ||
from keras.models import model_from_json | ||
|
||
|
||
class C3D: | ||
def __init__(self, model_path: Path, weights_path: Path): | ||
self.model = model_from_json(open(model_path.as_posix(), 'r').read()) | ||
print(self.model.summary()) | ||
self.model.load_weights(weights_path.as_posix()) | ||
self.model.compile(loss='mean_squared_error', optimizer='sgd') | ||
self.feature_extractor = backend.function([self.model.layers[0].input], | ||
[self.model.layers[11].get_output(train=False)]) | ||
|
||
def get_features(self, video: numpy.ndarray): | ||
frames = [] | ||
for frame in video: | ||
resized_frame = skimage.transform.resize(frame, (112, 112)) | ||
frames.append(resized_frame) | ||
resized_video = numpy.stack(frames) | ||
reshaped_video = numpy.moveaxis(resized_video[None, ...], [0, 1, 2, 3, 4], [0, 2, 3, 4, 1]) | ||
features = self.feature_extractor([reshaped_video])[0] | ||
features = numpy.moveaxis(features[0], [0, 1, 2, 3], [3, 0, 1, 2]) | ||
return features | ||
|
||
|
||
def save_c3d_features(videos_dirpath: Path, model_path: Path, weights_path: Path, output_dirpath: Path): | ||
""" | ||
C3D features from last conv layer; Dimension: 2x7x7x512 | ||
""" | ||
|
||
output_dirpath = output_dirpath / 'C3D' | ||
output_dirpath.mkdir(parents=True, exist_ok=False) | ||
c3d_model = C3D(model_path, weights_path) | ||
for video_path in tqdm(sorted(videos_dirpath.rglob('*.mp4'))): | ||
video = skvideo.io.vread(video_path.as_posix()) | ||
video_feature_map = c3d_model.get_features(video) | ||
output_path = output_dirpath / f'{video_path.stem}.npy' | ||
numpy.save(output_path.as_posix(), video_feature_map) | ||
return | ||
|
||
|
||
def demo1(): | ||
root_dirpath = Path('../../') | ||
videos_dirpath = root_dirpath / 'Data/Predicted_Videos' | ||
model_path = root_dirpath / 'Trained_Models/C3D/sports_1M.json' | ||
weights_path = root_dirpath / 'Trained_Models/C3D/sports1M_weights.h5' | ||
output_dirpath = root_dirpath / 'Data/SSA_Features' | ||
save_c3d_features(videos_dirpath, model_path, weights_path, output_dirpath) | ||
return | ||
|
||
|
||
def main(): | ||
demo1() | ||
return | ||
|
||
|
||
if __name__ == '__main__': | ||
print('Program started at ' + datetime.datetime.now().strftime('%d/%m/%Y %I:%M:%S %p')) | ||
start_time = time.time() | ||
try: | ||
main() | ||
except Exception as e: | ||
print(e) | ||
traceback.print_exc() | ||
end_time = time.time() | ||
print('Program ended at ' + datetime.datetime.now().strftime('%d/%m/%Y %I:%M:%S %p')) | ||
print('Execution time: ' + str(datetime.timedelta(seconds=end_time - start_time))) |
Oops, something went wrong.