Comments (6)
We need preprocessing to be part of the model, as a best practice.
I will look into adding a new offset
argument to Rescaling
to support this use case.
For the time being I would recommend using a Normalization
layer (from layers.experimental.preprocessing
). It can do both scaling and offsetting. Just set the weights correctly.
from keras-io.
Let's move the discussion to the PR.
from keras-io.
Yes, that seems like an issue. We should fix it.
from keras-io.
I'll be working on this and hope to get back to you with a PR soon.
Thanks for addressing the issue.
from keras-io.
It appears to me that the Rescaling layer used in the code can only support multiplicative op(s). Instead of using 1/255., I can use 1/127.5 but that will scale the data in range (0, 2) which is undesired.
In order to attain required normalisation range of (-1, 1), the inputs should be scaled as: x /= 127.5; x -= 1
or similar.
Should we replace the Rescaling layer with a new preprocess tf.function or use keras_applications.xception.preprocess_input that does exactly the same operation as above and pass it to ds.map?
@tf.function
def preprocess(x):
x /= 127.5
x -= 1
return x
ds = ds.map(lambda x, y: (preprocess(x), y), AUTOTUNE)
or
preprocess = tf.keras.applications.xception.preprocess_input
ds = ds.map(lambda x, y: (preprocess(x), y), AUTOTUNE)
Although, it wouldn't be a good idea to let go away the Rescaling layer from a documentation example as it'd then indirectly discourage users from using the new Preprocessing Layers; one workaround would be to use the Rescaling layer combined with a Lambda layer to scale inputs appropriately.
Something like this:
# x has range (0, 255)
x = tf.keras.layers.experimental.preprocessing.Rescaling(1 / 127.5)(x) # x has range (0, 2)
x = tf.keras.layers.Lambda(lambda inp: inp - 1.)(x) # x has range (-1, 1)
from keras-io.
Thanks @fchollet.
I'll make the code changes to the script, use the Normalization layer and submit a PR as of now. Also, hope to get back to you soon regarding the offset
argument for Rescaling
as well.
/cc: @tanzhenyu
We need preprocessing to be part of the model, as a best practice.
I will look into adding a new
offset
argument toRescaling
to support this use case.
We can have a discussion regarding the same. Thanks.
from keras-io.
Related Issues (20)
- Could not find TensorRT HOT 3
- Error occurred in the Named Entity Recognition using Transformers example HOT 6
- Support Distributed Training for Fine-tuning Stable Diffusion Example HOT 5
- kagglecatsanddogs_5340.zip not available to downoad - image_classification_from_scratch.py HOT 4
- Problem with training yolov8 on TPU
- model not converging the sparse categorical accuracy stays same for the whole epochs. HOT 6
- batch out of range & loss value becomes 'nan' when running monocular depth estimation HOT 6
- How to make individual predictions using the FNet example? HOT 4
- Multi-GPU distributed training with PyTorch
- [Movielens Example] Impossibile to save model: Cannot serialize object Ellipsis HOT 4
- TypeError: Sampler.__call__() got an unexpected keyword argument 'end_token_id' HOT 2
- ValueError: The filepath provided must end in `.keras` (Keras model format). Received: filepath=Model_ckpt.h5 HOT 9
- Hardware requirement for examples/rl/deep_q_network_breakout.py? HOT 5
- bayesian_neural_networks failed with Mixed Precision enabled HOT 3
- Would it be possible to make lstm_seq2seq support mixed precision? HOT 1
- Will it be a good Idea to add a tutorial to train a Image Classification suing ViT using CLS token. HOT 2
- Cannot export a slightly customized XLMRoberta model from keras_nlp HOT 1
- tutorial bug in consistency_training HOT 2
- Help runing the lastest version of ".\examples\vision\captcha_ocr.py" HOT 1
- Timeseries Classification Transformer: Last -> First HOT 1
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 keras-io.