Comments (6)
I like your proposal. If I understand correctly, in this new way of doing things a call to tf.pad
would be added inside the code for Conv2D
to handle more padding modes (like symmetric, reflect, constant padding)? And when not needed (zero-padding or valid) there would be no call to tf.pad
(to keep performance optimized)? And the API change would also permits passing explicit padding intervals (integers) per axis.
So the convolution padding would be defined as (to define the "geometry" of the padding):
class ConvPadding(enum.Enum):
"""An Enum holding the possible padding values for convolution modules."""
SAME = 'SAME'
VALID = 'VALID'
And the mode (what values are used to fill the padding):
class ConvPaddingMode(enum.Enum):
"""An Enum holding the possible padding values for convolution modules."""
SYM = 'SYM' # specify symmetric padding for spatial dim as tuple for H, W or single int
REFLECT = 'REFLECT'
MEAN = 'MEAN'
# ... and so on.
If I understand correctly, that's what you encapsulated in the proposed Padding
dataclass.
I would prefer to pass two arguments to Conv2D.__init__
instead (to keep the code accessible, we voluntarily limit abstractions to keep the code more welcoming to people of varied CS experience).
ConvPaddingInt = Union[Sequence[Tuple[int, int]], Tuple[int, int], int]
class Conv2D(...):
def __init__(self,
...
padding: Union[ConvPadding, ConvPaddingInt] = ConvPadding.SAME,
padding_mode: Union[ConvPaddingMode, float] = 0,
...
Would this variant of your initial proposal work for you?
from objax.
@david-berthelot TLDR yes, I think the above proposal would work great despite confusion over my poor choice of the term 'symmetric'
Regarding 'symmetric', I wasn't actually thinking modes while trying to jot down the idea. My additional enum values were all ways of specifying the 'geometries' (or 'padding type'). I was proposing different alternatives dataclass w/ extended enum vs union as I wasn't sure if single types were preferred over unions for interfaces here.
So 'symmetric' referred to the fact that the int and Tuple[int, int] result in symmetric amounts of padding -- pad_beg == pad_end with no ability to end up with beg != end as with 'SAME' padding.
As for the modes, that'd also be useful for some less common use cases and covered by calling pad before the conv as you mention. I use 'circular' and 'constant' from time to time, but not 'reflect', 'symmetric', 'replicate'.
from objax.
Would you be open to contributing a PR? If not please let me know; I, or someone else, can follow up.
from objax.
@david-berthelot I would be, currently I have part of the change (padding type, not the mode) intertwined with some others for my prototyping. Once I get a bit further on that and get a chance to test properly I can do a PR here. But if someone else wants to take it on here before that happens, that's a-ok.
from objax.
Here's the plan, I collected more opinions and we'll extend in the simplest way, I'll do the coding in the coming days.
This part will remain the same.
class ConvPadding(enum.Enum):
"""An Enum holding the possible padding values for convolution modules."""
SAME = 'SAME'
VALID = 'VALID'
Conv2D (and others) will be extended to support numeric padding.
ConvPaddingInt = Union[Sequence[Tuple[int, int]], Tuple[int, int], int]
class Conv2D(...):
def __init__(self,
...
padding: Union[ConvPadding, ConvPaddingInt] = ConvPadding.SAME,
...
In the end, we decided againt added numpy-style mode paddings since we want to be mindful about keeping the original design simplicity.
from objax.
@david-berthelot makes a lot of sense, the numeric padding was the motivation for this issue. Fancy modes are much less common and can always be done with separate padding layers.
from objax.
Related Issues (20)
- If user won't add random generator to VarCollection of jitted code then same number always return by random generator
- Model compiling twice when using jax==0.2.10 or later HOT 6
- Update Objax Basics tutorial to reflect .value change
- Accessing variable of a vectorized module HOT 2
- objax.Jit reports error when StateVar is added to the vc argument HOT 3
- Regression of JAX duck typing. HOT 2
- RecursionError when attempting to unpickle objax objects HOT 2
- How to compute Jacobian of outputs w.r.t. inputs HOT 3
- Activation functions like Swish and Mish are absent. HOT 1
- Error due to the deprecation of jax.api
- objax.Jacobian and objax.Hessian similar to objax.Grad HOT 4
- replacing jax.vmap with objax.Vectorize HOT 3
- Closure scoping for nested objax.Functions HOT 2
- ResNetV2 from model.zoo does not specify train arg for ResNetV2Block HOT 2
- pmean inside objax.parallel causes multithreading deadlock for more than 2 gpus HOT 3
- `objax.variable.VarCollection.update` fails when passing `Dict[str, Any]` HOT 1
- `objax.variable.VarCollection.update` not compliant with key-value assignment HOT 1
- TypeError during gradient computation: type <class 'objax.variable.TrainVar'> is not a valid JAX type
- Missing release 1.7.0 on GitHub HOT 2
- [Jax 0.4.27] AttributeError: arr.device_buffers has been deprecated.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objax.