Compare outputs between layers written in Tensorflow and layers written in Pytorch

Overview

Compare outputs of Wasserstein GANs between TensorFlow vs Pytorch

This is our testing module for the implementation of improved WGAN in Pytorch

Prerequisites

How to run

Go to test directory and run python test_compare_tf_to.py

How we do it

We inject the same weights init and inputs into layers of TensorFlow and Pytorch that we want to compare. For example, we set 5e-2 for the weights of Conv2d layer in both TensorFlow and Pytorch. Then we passed the same random input to those 2 layers and finally we compared 2 outputs from TensorFlow tensor and Pytorch tensor.

We use cosine to calculate the distance between 2 outputs. Reference: scipy.spatial.distance.cosine

What were compared between TensorFlow and Pytorch

We've compared the implementation of several layers in WGAN model. They are:

  • Depth to space
  • Conv2d
  • ConvMeanPool
  • MeanPoolConv
  • UpsampleConv
  • ResidualBlock (up)
  • ResidualBlock (down)
  • GoodGenerator
  • Discriminator
  • LayerNorm
  • BatchNorm
  • Gradient of Discriminator
  • Gradient of LayerNorm
  • Gradient of BatchNorm

Result

There are some weird results (cosine < 0 or the distance is bigger than defined threshold - 1 degree) and we look forward to your comments. Here are the outputs of the comparison.

b, c, h, w, in, out: 512, 12, 32, 32, 12, 4

-----------gen_data------------
True
tf.abs.mean: 0.500134
to.abs.mean: 0.500134
diff.mean: 0.0
cosine distance of gen_data: 0.0

-----------depth to space------------
True
tf.abs.mean: 0.500047
to.abs.mean: 0.500047
diff.mean: 0.0 cosine distance of depth to space: 0.0

-----------conv2d------------
True
tf.abs.mean: 2.5888
to.abs.mean: 2.5888
diff.mean: 3.56939e-07
cosine distance of conv2d: 5.96046447754e-08

-----------ConvMeanPool------------
True
tf.abs.mean: 2.58869
to.abs.mean: 2.58869
diff.mean: 2.93676e-07
cosine distance of ConvMeanPool: 0.0

-----------MeanPoolConv------------
True
tf.abs.mean: 2.48026
to.abs.mean: 2.48026
diff.mean: 3.42314e-07
cosine distance of MeanPoolConv: 0.0

-----------UpsampleConv------------
True
tf.abs.mean: 2.64478
to.abs.mean: 2.64478
diff.mean: 5.50668e-07
cosine distance of UpsampleConv: 0.0

-----------ResidualBlock_Up------------
True
tf.abs.mean: 1.01438
to.abs.mean: 1.01438
diff.mean: 5.99736e-07
cosine distance of ResidualBlock_Up: 0.0

-----------ResidualBlock_Down------------
False
tf.abs.mean: 2.38841
to.abs.mean: 2.38782
diff.mean: 0.192403
cosine distance of ResidualBlock_Down: 0.00430130958557

-----------Generator------------
True
tf.abs.mean: 0.183751
to.abs.mean: 0.183751
diff.mean: 9.97704e-07
cosine distance of Generator: 0.0

-----------D_input------------
True
tf.abs.mean: 0.500013
to.abs.mean: 0.500013
diff.mean: 0.0
cosine distance of D_input: 0.0

-----------Discriminator------------
True
tf.abs.mean: 295.795
to.abs.mean: 295.745
diff.mean: 0.0496472
cosine distance of Discriminator: 0.0

-----------GradOfDisc------------
GradOfDisc
tf: 315944.9375
to: 315801.09375
True
tf.abs.mean: 315945.0
to.abs.mean: 315801.0
diff.mean: 143.844
cosine distance of GradOfDisc: 0.0

-----------LayerNorm-Forward------------
True
tf.abs.mean: 0.865959
to.abs.mean: 0.865946
diff.mean: 1.3031e-05
cosine distance of LayerNorm-Forward: -2.38418579102e-07

-----------LayerNorm-Backward------------
False
tf.abs.mean: 8.67237e-10
to.abs.mean: 2.49221e-10
diff.mean: 6.18019e-10
cosine distance of LayerNorm-Backward: 0.000218987464905

-----------BatchNorm------------
True
tf.abs.mean: 0.865698
to.abs.mean: 0.865698
diff.mean: 1.13394e-07
cosine distance of BatchNorm: 0.0

-----------BatchNorm-Backward------------
True
tf.abs.mean: 8.66102e-10
to.abs.mean: 8.62539e-10
diff.mean: 3.56342e-12
cosine distance of BatchNorm-Backward: 4.17232513428e-07

Acknowledge

Owner
Hung Nguyen
Hung Nguyen
Pneumonia Detection using machine learning - with PyTorch

Pneumonia Detection Pneumonia Detection using machine learning. Training was done in colab: DEMO: Result (Confusion Matrix): Data I uploaded my datase

Wilhelm Berghammer 12 Jul 07, 2022
Bravia core script for python

Bravia-Core-Script You need to have a mandatory account If this L3 does not work, try another L3. enjoy

5 Dec 26, 2021
[CVPR'21] DeepSurfels: Learning Online Appearance Fusion

DeepSurfels: Learning Online Appearance Fusion Paper | Video | Project Page This is the official implementation of the CVPR 2021 submission DeepSurfel

Online Reconstruction 52 Nov 14, 2022
Refactoring dalle-pytorch and taming-transformers for TPU VM

Text-to-Image Translation (DALL-E) for TPU in Pytorch Refactoring Taming Transformers and DALLE-pytorch for TPU VM with Pytorch Lightning Requirements

Kim, Taehoon 61 Nov 07, 2022
PyTorch implementation of saliency map-aided GAN for Auto-demosaic+denosing

Saiency Map-aided GAN for RAW2RGB Mapping The PyTorch implementations and guideline for Saiency Map-aided GAN for RAW2RGB Mapping. 1 Implementations B

Yuzhi ZHAO 20 Oct 24, 2022
Towards End-to-end Video-based Eye Tracking

Towards End-to-end Video-based Eye Tracking The code accompanying our ECCV 2020 publication and dataset, EVE. Authors: Seonwook Park, Emre Aksan, Xuco

Seonwook Park 76 Dec 12, 2022
The end-to-end platform for building voice products at scale

Picovoice Made in Vancouver, Canada by Picovoice Picovoice is the end-to-end platform for building voice products on your terms. Unlike Alexa and Goog

Picovoice 318 Jan 07, 2023
FastFCN: Rethinking Dilated Convolution in the Backbone for Semantic Segmentation.

FastFCN: Rethinking Dilated Convolution in the Backbone for Semantic Segmentation [Project] [Paper] [arXiv] [Home] Official implementation of FastFCN:

Wu Huikai 815 Dec 29, 2022
A TensorFlow implementation of FCN-8s

FCN-8s implementation in TensorFlow Contents Overview Examples and demo video Dependencies How to use it Download pre-trained VGG-16 Overview This is

Pierluigi Ferrari 50 Aug 08, 2022
Does Pretraining for Summarization Reuqire Knowledge Transfer?

Pretraining summarization models using a corpus of nonsense

Approximately Correct Machine Intelligence (ACMI) Lab 12 Dec 19, 2022
Sharpness-Aware Minimization for Efficiently Improving Generalization

Sharpness-Aware-Minimization-TensorFlow This repository provides a minimal implementation of sharpness-aware minimization (SAM) (Sharpness-Aware Minim

Sayak Paul 54 Dec 08, 2022
The implementation of the algorithm in the paper "Safe Deep Semi-Supervised Learning for Unseen-Class Unlabeled Data" published in ICML 2020.

DS3L This is the code for paper "Safe Deep Semi-Supervised Learning for Unseen-Class Unlabeled Data" published in ICML 2020. Setups The code is implem

Guolz 36 Oct 19, 2022
A pytorch reprelication of the model-based reinforcement learning algorithm MBPO

Overview This is a re-implementation of the model-based RL algorithm MBPO in pytorch as described in the following paper: When to Trust Your Model: Mo

Xingyu Lin 93 Jan 05, 2023
Official Pytorch implementation of 'GOCor: Bringing Globally Optimized Correspondence Volumes into Your Neural Network' (NeurIPS 2020)

Official implementation of GOCor This is the official implementation of our paper : GOCor: Bringing Globally Optimized Correspondence Volumes into You

Prune Truong 71 Nov 18, 2022
Car Price Predictor App used to predict the price of the car based on certain input parameters created using python's scikit-learn, fastapi, numpy and joblib packages.

Pricefy Car Price Predictor App used to predict the price of the car based on certain input parameters created using python's scikit-learn, fastapi, n

Siva Prakash 1 May 10, 2022
RIFE: Real-Time Intermediate Flow Estimation for Video Frame Interpolation

RIFE RIFE: Real-Time Intermediate Flow Estimation for Video Frame Interpolation Ported from https://github.com/hzwer/arXiv2020-RIFE Dependencies NumPy

49 Jan 07, 2023
A Deep Learning based project for creating line art portraits.

ArtLine The main aim of the project is to create amazing line art portraits. Sounds Intresting,let's get to the pictures!! Model-(Smooth) Model-(Quali

Vijish Madhavan 3.3k Jan 07, 2023
Fluency ENhanced Sentence-bert Evaluation (FENSE), metric for audio caption evaluation. And Benchmark dataset AudioCaps-Eval, Clotho-Eval.

FENSE The metric, Fluency ENhanced Sentence-bert Evaluation (FENSE), for audio caption evaluation, proposed in the paper "Can Audio Captions Be Evalua

Zhiling Zhang 13 Dec 23, 2022
tmm_fast is a lightweight package to speed up optical planar multilayer thin-film device computation.

tmm_fast tmm_fast or transfer-matrix-method_fast is a lightweight package to speed up optical planar multilayer thin-film device computation. It is es

26 Dec 11, 2022
[TNNLS 2021] The official code for the paper "Learning Deep Context-Sensitive Decomposition for Low-Light Image Enhancement"

CSDNet-CSDGAN this is the code for the paper "Learning Deep Context-Sensitive Decomposition for Low-Light Image Enhancement" Environment Preparing pyt

Jiaao Zhang 17 Nov 05, 2022