Skip to content

Instantly share code, notes, and snippets.

View alidastgheib's full-sized avatar

Mohammad Ali Dastgheib alidastgheib

View GitHub Profile
@alidastgheib
alidastgheib / README.md
Created May 13, 2021 02:34 — forked from tommct/README.md
Instructions for downloading Jupyter Notebooks from Coursera

From an open Jupyter Notebook homework assignment, select "Coursera" to take you to the home page. Make a new notebook and fill it with the following and excute the cell with:

%%bash
tar cvfz hw.tar.gz .

This may take a little while to run depending on the packages. Select "Coursera" again to take you to the Home directory. Check the hw.tar.gz file and then Download. After the file is downloaded, delete it.

import keras.backend as K
import tensorflow as tf
def samplewise_tf_dct(x_sample):
print('=======> input of "samplewise_tf_dct"')
print(type(x_sample))
print((x_sample.shape))
print(x_sample)
output_list = []
import keras.backend as K
def samplewise_tf_dct(x_sample):
print('=======> input of "samplewise_tf_dct"')
print(type(x_sample))
print((x_sample.shape))
print(x_sample)
for idx_channel in range(x_sample.shape[-1]):
x_sample[:, :, idx_channel] = K.spectral.dct(K.transpose(K.spectral.dct(x_sample[:, :, idx_channel]))) # a 2D DCT
@alidastgheib
alidastgheib / gist:64f4491e00c13dd04c0494eb579572a4
Created January 29, 2019 19:13
performing "DCT transform" using Lambda layer
import keras.backend as K # which is Tensorflow
def dct_layer_function(x_batch):
output = K.zeros(x_batch.shape)
batch_size = x_batch.shape[0]
channel_size = x_batch.shape[-1]
for idx_batch in range(batch_size):
for idx_channel in range(channel_size):
output[idx_batch, :, :, idx_channel] = K.spectral.dct(