Theano / Theano

Theano was a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It is being continued as PyTensor: www.github.com/pymc-devs/pytensor

Home Page:https://www.github.com/pymc-devs/pytensor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Theano lack a check for unreasonable parameters like 'dilation_rate=0' in `Conv2D`or `DepthwiseConv2D`

shiningrain opened this issue · comments

System information

  • Have I written custom code (as opposed to using example directory):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 & Linux Ubuntu 18.04
  • Theano backend (yes/no): yes
  • Theano version:1.0.4
  • Python version: 3.6.9
  • CUDA/cuDNN version: -
  • GPU model and memory: -

Describe the current behavior
When I use a dangerous corner case dilation_rate=0 in Conv2Dor DepthwiseConv2D, Theano doesn't detect this unreasonable parameter and uses it to build a model. This unexpected behaviour confuses me a lot. Theoretically, the dilation_rate=0 should be incorrect in the convolution operation.

Does dilation_rate=0 have some special meaning in Theano? I have not found any descriptions about this case in documents. If no special meaning, Should Theano set a check for such unreasonable parameters to avoid the risks and incorrect usages in the model?

Code to reproduce the issue

import os
import numpy as np
import keras.layers as L
import keras.backend as K
from layer_test import set_keras_backend
import importlib
from keras.engine import Model, Input

## Using Theano as Keras backend.
## Input dtype default is float32

layer = 'DepthwiseConv2D'  # or 'Conv2D'
#kwargs for DepthwiseConv2D
kwargs={
  'data_format': 'channels_first',
  'dilation_rate': 0,
  'kernel_size': 3, 
  'padding': 'valid', 
  'strides': 3}

# kwargs for Conv2D
# kwargs = {
# 'filters': 9, 
# 'kernel_size': 4,
# 'padding': 'valid', 
# 'strides': 4, 
# 'dilation_rate': 0, 
# 'data_format': 'channels_last'}
 
input_data = (10 * np.random.random((1,32,32,16)))
input = input_data.astype('float32')
model_path = os.path.join('./', 'model.h5')
layer_cls = getattr(L, layer)
layer = layer_cls(**kwargs)
x = Input(batch_shape=input.shape)
y = layer(x)
bk_model =Model(x, y)
bk_model.save(model_path, bk_model)
print('finish')

Your proposition looks good. Theano is barely maintained now. So do not expect anyone to do this.
If you or someone else make a PR for this, I'll review it as it should be small.

Your proposition looks good. Theano is barely maintained now. So do not expect anyone to do this.
If you or someone else make a PR for this, I'll review it as it should be small.

Thank you very much for your reply. I will try to make a PR for this later. Thank you again

I'm browsing this repo for nostalgia. Just curious, why does anyone still use Theano in 2020? Is it because of legacy code? But then what legacy code is useful in 2020, now that almost all major algorithms have implementations in TF and/or PyTorch? No offense, just wondering.

PyMC3 is still using Theano. They didn't found a better back-end for their need up to now.
This is one example where Theano is actively being used.