Tensorflow 2.0 : frozen graph support [closed] - tensorflow2.0

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Will the support for frozen graph continue in tensorflow 2.0 or deprecated?
I mean the scripts and APIs to create/optimize frozen graph from saved_model. Also the APIs to run the inference for the same.
Assuming it will be supported in future, what is the recommended method to run the inference on frozen graph in tensorflow 2.0 ?

The freeze graph APIs - freeze_graph.py and converter_variables_to_constants - will not be supported in TensorFlow 2.0.
In 2.0, the primary export format is SavedModels so APIs are built to directly support SavedModels.
Inference on existing frozen graphs can be run using the v1.compat path.

Now, freeze_graph is officially gone with TensorFlow 2.0 stable release.
Check Here.

if you use estimator to biuld a model, you can using tf.estimator.Estimator.export_saved_model to freeze your model.
model = tf.estimator.Estimator(
model_fn=model_fn,
model_dir=model_saved_dir)
def serving_input_receiver_fn():
# in here, my input is 512 x 512 single channel image
feature = tf.compat.v1.placeholder(tf.float32, shape=[None, 512, 512, 1], name="inputs")
return tf.estimator.export.TensorServingInputReceiver(feature, feature)
model.export_saved_model(model_saved_dir, serving_input_receiver_fn)
this code is work in tensorflow 2.0
or you use keras, You can refer to the steps of the official website
https://www.tensorflow.org/tutorials/keras/save_and_load#savedmodel_format

Related

Pretrained alexnet in tensorflow [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 12 months ago.
Improve this question
I want to use pretrained Alexnet for transfer learning. I dont see its available in Keras library.
Am I missing something here?
Other Alternative I see here is to create model and
load pretrained weight
train from scratch
Training from scratch using imagenet dataset is not possible for me due to resource constraint.
Loading pre-trained weight will work.
Would you provide any pointers for getting the pretrained weight for Alexnet?
Thanks,
As of right now, Keras does not (officially) seem to offer a pre-trained AlexNet model. PyTorch, on the other hand, does. If you are willing to use a different framework for the task, you can use PyTorch. You can retrieve a pre-trained version of the AlexNet like so:
import torchvision.models as models
alexnet = models.alexnet(pretrained=True)
You can find the list of available pre-trained models here, and a transfer learning tutorial for image classification here.
Hope that answers your question!

need guidance on using pre-trained weights in segmentation_models API [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to use a pre-trained Unet model using segmentation_models API for the Cityscapes dataset, but I need the pre-trained weights for the same. Where can I find the pre-trained weights for a Unet model trained on the Cityscapes dataset?
Please guide me on this!!!
UNet is absent from the benchmark so i assume it is not adapted for this dataset (too slow and not enough performant probably). However, I advise you to start with DeepLabv3+ from Google which is not so complicated and more adapted for this dataset.
You can use this repository where it is implemented, well documented and useable with pretrained weights from cityscape dataset (and also PascalVOC dataset).

How to use Variational Autoencoder as a Feature Extractor? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to use my VAE trained on an image dataset as a feature extractor for another task, so that I could for example replace a ResNet for feature extraction with my VAE.
Which Layers do I use for this?
With "standard" autoencoders you just take the encoding network, but since the latent layer of the VAE consist of mean and distribution I do not know which layers I should use for feature extraction.
Does somebody know how to use a VAE as a feature extractor and what to consider with using different components?
Hidden variables z are used in VAEs as the extracted features for dimensionality reduction. Here is an example dimensionality reduction from four features in the original space ([x1,x2,x3,x4]) to two features in the reduced space ([z1,z2]) (source):
Once you have trained the model, you can pass a sample to the encoder it extracts the features. You may find a Keras implementation example on mnist data here (see the plot_label_clusters function):

I cannot train my model using transfer learning (VGG16) on my GPU [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to use transfer learning to train my model to detect diseases in rice on images of the plant. I attempted using VGG16, but I could not get it to train with my GPU. I have an NVIDIA GeForce MX150.
Below is the code that I used to fit the model:
import tensorflow as tf
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
with tf.device('/device:GPU:1'):
# fit the model
r = model.fit(
training_set,
validation_data=test_set,
epochs=20,
steps_per_epoch=len(training_set),
validation_steps=len(test_set)
)
Tensorflow GPU support requires a few dependencies. Please see https://www.tensorflow.org/install/gpu
Then, try tf.test.is_gpu_available() - if this is True, then your GPU is being used for training.
On a single GPU, you should not need to use with to train on GPU. For me to help more, please provide any logs or errors.

tf.nn.relu vs tf.keras.activations.relu [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
The community reviewed whether to reopen this question last month and left it closed:
Original close reason(s) were not resolved
Improve this question
I see both tf.nn.relu and tf.keras.activations.relu computes only the ReLU function (no additional fully connected layer or something, as described here), so what's the difference between them? Does one just wraps the other?
tf.nn.relu : It comes from TensorFlow library. It is located in the nn module. Hence, it is used as an operation in neural networks. If x is a tensor then,
y = tf.nn.relu( x )
It is used in creating custom layers and NN. If you use it with Keras, you may face some problems while loading or saving the models or converting the model to TF Lite.
tf.keras.activations.relu : It comes from the Keras library included in TensorFlow. It is located in the activations module which also provides another activation functions. It is mostly used in Keras Layers ( tf.keras.layers ) for the activation= argument :
model.add( keras.layers.Dense( 25 , activation=tf.keras.activations.relu ) )
But, it can also be used as the example in the above section. It is more specific to Keras ( Sequential or Model ) rather than raw TensorFlow computations.
tf.nn.relu is a TensorFlow specific whereas tf.keras.activations.relu has more uses in Keras own library. If I create a NN with only TF, I will most probably use tf.nn.relu and if I am creating a Keras Sequential model then I will use tf.keras.activations.relu.