Comments (12)
Yes, it is fairly easy, taking the example https://github.com/tflearn/tflearn/blob/master/examples/images/dnn.py, you can add at the end of the file:
# Save the model
model.save('my_model')
# Redefine a model with desired layer as output
model = tflearn.DNN(dense2)
# Load weights from saved model
model.load('my_model')
# Get features for X[0]
model.predict([X[0]])
from tflearn.
Hi,
My Network definition performs data pre-processing and augmentation using the following code before network definition:
===== CODE Pre-processing =====
img_prep = ImagePreprocessing()
img_prep.add_featurewise_zero_center()
img_prep.add_featurewise_stdnorm()
img_aug = ImageAugmentation()
img_aug.add_random_flip_leftright()
I would like to know that: "is it necessary to do the above pre-processing before extracting features for new images?". If yes, then please let me know how.
Thanks a lot in advance.
from tflearn.
If you trained your images using pre-processing, then pictures should always be pre-processed before you are going to predict (and extract features), otherwise results might changed a lot and not be consistent. But this pre-processing is done automatically by TFLearn (When training, testing and predicting), so you do not have to worry about it. Note that only data preprocessing is applied when predicting, not augmentation.
Also, I realized there was a bug when using model.predict(); it was not performing the pre-processing. I just fixed it, please re-install TFLearn and it should work fine.
from tflearn.
Thank you for your answer. Indeed, I was applying the pre-processing before predicting and not getting the expected results. Therefore, I was wondering whether the TFLearn pre-processing has an additional impact on the test data.
Thanks for fixing the bug. I re-installed TFLearn and tried to test it again. However, I observe the following error message now:
tensorflow.python.framework.errors.NotFoundError: Tensor name "DataPreprocessing/pc" not found in checkpoint files
It seems the change you have made is not compatible with the pre-tained models. Is it possible to fix this error.
Thanks.
from tflearn.
Arf... yes, I added ZCA Whitening (That added the Principal Component variable to the graph). You can either retrain your model if possible, or just add a quick fix:
In the file: https://github.com/tflearn/tflearn/blob/master/tflearn/data_preprocessing.py#L30, Replace the PersistentParameter by 'None'. This should works well as long as your are not using ZCA Whitening.
Or without modifying tflearn library, add to your script (before loading model):
tf.add_to_collection(tf.GraphKeys.EXCL_RESTORE_VARS, 'pc')
or
tf.add_to_collection(tf.GraphKeys.EXCL_RESTORE_VARS, img_prep.global_pc.var)
tf.add_to_collection(tf.GraphKeys.EXCL_RESTORE_VARS, img_prep.global_pc.var_r)
from tflearn.
Thanks a lot. Unfortunately adding those lines did not solve the problem. Therefore, I prefer to re-train from the beginning.
from tflearn.
After re-training I tried to extract the features following the same way as before. However, I get the following error message now when I execute "ft = model.predict([X[0]])":
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/tflearn/models/dnn.py", line 199, in predict
return self.predictor.predict(feed_dict)
File "/usr/local/lib/python2.7/dist-packages/tflearn/helpers/evaluator.py", line 63, in predict
feed_dict[k] = dprep_dict[k].apply(feed_dict[k])
File "/usr/local/lib/python2.7/dist-packages/tflearn/data_preprocessing.py", line 37, in apply
batch = m(batch)
File "/usr/local/lib/python2.7/dist-packages/tflearn/data_preprocessing.py", line 187, in _featurewise_zero_center
batch[i] -= self.global_mean.value
TypeError: ufunc 'subtract' output (typecode 'O') could not be coerced to provided output parameter (typecode 'f') according to the casting rule ''same_kind''
from tflearn.
Thanks for reporting the issue, there was actually a bug that the global mean variable was not restored when loading a model. I updated the code so it should work now, please reinstall TFLearn.
from tflearn.
Thanks a lot. Now it is working as expected. Moreover, it verified my earlier assumption that the additional pre-processing has impact on the performance.
from tflearn.
Hi,
After updating tflearn today I faced similar issue:
File "/cs/vml4/smuralid/.pyenv/versions/2.7.12/lib/python2.7/site-packages/tflearn/data_preprocessing.py", line 201, in _featurewise_zero_center
batch[i] -= self.global_mean.value
TypeError: ufunc 'subtract' output (typecode 'O') could not be coerced to provided output parameter (typecode 'd') according to the casting rule ''same_kind''
Please help me fix it.
UPDATE:
Sorry I found the problem. I created the preprocessing function outside of the scope of my session/graph.
from tflearn.
I also have the same issue.
I'm using tflearn-0.3.2
which version is this updated in?
from tflearn.
I'm having the same issue as well
tflearn==0.3.2
from tflearn.
Related Issues (20)
- No swish activation function? HOT 1
- HELLO? ANYBODY HOME? HOT 1
- Syntax warnings due to comparison of literals using is
- Error in TF2.0... Any ideas? HOT 3
- #001 'unicodeescape' code can't decode bytes in position 2-3: truncated \UXXXXXXXX escape HOT 1
- Update required HOT 1
- Not working with tensorflow 2.3.1 HOT 5
- Import error
- ValueError: Cannot feed value of shape (61,) for Tensor 'InputData/X:0', which has shape '(?, 61)' HOT 1
- Examples
- Xception Example model
- def variance_scaling in initializations.py tries to call deprecated class
- LSTM stateful?
- why i got same number with Alexnet ? HOT 1
- Why tflearn disables executing eagerly ? HOT 2
- OSS License compatibility question
- tflearn import issue HOT 5
- Pillow 10 breaks tflearn import HOT 2
- Requesting Review for pull request #1176
- Use github.com/apssouza22/chatflow as a conversational layer. It would enable actual API requests to be carried out from natural language inputs.
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 tflearn.