category
stringclasses
107 values
title
stringlengths
15
179
question_link
stringlengths
59
147
question_body
stringlengths
53
33.8k
answer_html
stringlengths
0
28.8k
__index_level_0__
int64
0
1.58k
tenserflow
Keras 2.13.1 on Windows: ModuleNotFoundError: No module named 'tensorflow.keras'
https://stackoverflow.com/questions/76828324/keras-2-13-1-on-windows-modulenotfounderror-no-module-named-tensorflow-keras
<p>I'm using, on a Windows 11 Pro PC, Python 3.11 and I'm trying to import Tenserflow and Keras for this test program:</p> <pre><code>from sklearn.datasets import load_breast_cancer from sklearn.model_selection import train_test_split from tensorflow.keras.models import Sequential from tensorflow.keras.layers import De...
734
tenserflow
Python Tenserflow/Chatgpts gymnasiam for deep reinforcement learning errors
https://stackoverflow.com/questions/78222729/python-tenserflow-chatgpts-gymnasiam-for-deep-reinforcement-learning-errors
<p>I dont understand these errors im getting can someone please explain it to me?</p> <p>''' Traceback (most recent call last): File &quot;C:\Users\pacym\DRL_AERIATIONBASIN\pythonProject1\SQL.py&quot;, line 4, in import tensorflow as tf File &quot;C:\Users\pacym\DRL_AERIATIONBASIN\pythonProject1.venv\Lib\site-packages...
735
tenserflow
TenserFlow, How to save style transfer model for later use?
https://stackoverflow.com/questions/64921166/tenserflow-how-to-save-style-transfer-model-for-later-use
<p>I've been using <a href="https://www.tensorflow.org/tutorials/generative/style_transfer#calculate_style" rel="nofollow noreferrer">this</a> tutorial from TensorFlow's site to create a <a href="https://gist.github.com/daniel-keller/1d36b4e225b161cc375a3c26d27e0be6" rel="nofollow noreferrer">script</a> (python3) that ...
<p>Use <code>model.save()</code> method.</p> <p>Read this tutorial: <a href="https://www.tensorflow.org/guide/keras/save_and_serialize" rel="nofollow noreferrer">https://www.tensorflow.org/guide/keras/save_and_serialize</a></p>
736
tenserflow
How to select a tf-serving version?
https://stackoverflow.com/questions/54489735/how-to-select-a-tf-serving-version
<p>If I use tenserflow 1.8 or tensorflow 1.12, which version of tf-version I can use for inference? Is it have a requirement that if I use tenserflow 1.8 then I should choose corresponding tf-serving r1.8? Or we just use the master branch is ok?</p>
<p>Yes, it's best to use the version of TF Serving that corresponds to the version of TensorFlow your model was trained with. You can check out the releases of TF Serving on <a href="https://github.com/tensorflow/serving/releases" rel="nofollow noreferrer">github</a>. </p>
737
tenserflow
How to get rid from this error while downloading tensorflow?
https://stackoverflow.com/questions/48880649/how-to-get-rid-from-this-error-while-downloading-tensorflow
<pre><code> Exception: Traceback (most recent call last): File "c:\program files\python36\lib\site-packages\pip\basecommand.py", line 215, in main status = self.run(options, args) File "c:\program files\python36\lib\site-packages\pip\commands\install.py", line 342, in run prefix=options.prefix_path, Fil...
<p>bassed on this last part of your traceback:</p> <pre><code>mkdir(name, mode) PermissionError: [WinError 5] Access is denied </code></pre> <p>you dont have permission to create directories</p> <p>start your commandline as admin and try again</p>
738
tenserflow
Calculate object distance from camera with Tenserflow in Android
https://stackoverflow.com/questions/60408106/calculate-object-distance-from-camera-with-tenserflow-in-android
<pre><code>final List&lt;ObjectionDetector.Recognition&gt; mappedRecognitions = new LinkedList&lt;&gt;(); for (final ObjectionDetector.Recognition result : results) { final RectF location = result.getLocation(); } </code></pre>
739
tenserflow
I am not able to importing keras efficientnet B0 even I installed keras-efficientnets
https://stackoverflow.com/questions/68013868/i-am-not-able-to-importing-keras-efficientnet-b0-even-i-installed-keras-efficien
<pre><code>from keras_efficientnets import EfficientNetB0 AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects' </code></pre> <p>I installed keras-efficientnets, I installed tenserflow, but it is showing error while importing.</p>
740
tenserflow
spyder ModuleNotFoundError: No module named &#39;object_detection &#39;
https://stackoverflow.com/questions/70933750/spyder-modulenotfounderror-no-module-named-object-detection
<pre><code>!python {SCRIPTS_PATH + '/generate_tfrecord.py'} -x {IMAGE_PATH + '/train'} -l {ANNOTATION_PATH + '/label_map.pbtxt'} -o {ANNOTATION_PATH + '/train.record'} !python {SCRIPTS_PATH + '/generate_tfrecord.py'} -x{IMAGE_PATH + '/test'} -l {ANNOTATION_PATH + '/label_map.pbtxt'} -o {ANNOTATION_PATH + '/test.record'...
<p>That error is caused because tensorflow-object-detection has not been installed.</p> <p>Follow this <a href="https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html#tensorflow-object-detection-api-installation" rel="nofollow noreferrer">page</a> to install</p>
741
tenserflow
Using more than 1 metric in pytorch
https://stackoverflow.com/questions/71404067/using-more-than-1-metric-in-pytorch
<p>I have some experience in Tenserflow but I'm new to pytorch. Sometimes I need more than 1 metric to check the accuracy of training. In Tenserflow, I used to do as shown below. But I wonder how could list more than 1 metric in pytorch.</p> <pre><code>LR = 0.0001 optim = keras.optimizers.Adam(LR) dice_loss_se2 = sm.l...
<p>In pytorch training is done mostly through loops so you have define via each step, there are packages like torchmetrics which you can run each metric heres an example:</p> <pre class="lang-py prettyprint-override"><code>import torchmetrics for step, (test_image, test_labels) in tqdm(enumerate(test_dataloader), tota...
742
tenserflow
Tensorflow Installation Error in Conda Environment
https://stackoverflow.com/questions/62879867/tensorflow-installation-error-in-conda-environment
<p>I am trying to install Tenserflow through <a href="https://docs.conda.io/en/latest/" rel="nofollow noreferrer">Conda</a>. When I run:</p> <p><code>pip install --upgrade tensorflow</code></p> <p>I get the following error:</p> <pre><code>Collecting tensorflow Downloading tensorflow-2.2.0-cp36-cp36m-win_amd64.whl (45...
<p>Please follow the link given below. This has helped me and my friends a lot of times.</p> <p><a href="https://youtu.be/O8yye2AHCOk" rel="nofollow noreferrer">https://youtu.be/O8yye2AHCOk</a></p>
743
tenserflow
Couldn&#39;t install tenserflow on Windows10 with python --version 3.5.3. (64 bit)
https://stackoverflow.com/questions/44189048/couldnt-install-tenserflow-on-windows10-with-python-version-3-5-3-64-bit
<p><strong>Trying to install TensorFlow</strong> </p> <p><strong>Installing with native pip</strong></p> <p><em>Error:</em></p> <pre><code>C:\Users\Sourav&gt;pip3 install --upgrade tensorflow Collecting tensorflow Could not find a version that satisfies the requirement tensorflow (from versions: ) No matching dist...
<p><strong><em>Finally found a solution.</em></strong></p> <p><strong>Installing with Anaconda</strong></p> <pre><code>conda create --name tensorflow python=3.5 activate tensorflow conda install jupyter conda install scipy pip install tensorflow or pip install tensorflow-gpu </code></pre> <p>It is important to add p...
744
tenserflow
Serialized data doesn&#39;t match deserialized data in tenserflow TFRecordDataset code
https://stackoverflow.com/questions/49633220/serialized-data-doesnt-match-deserialized-data-in-tenserflow-tfrecorddataset-co
<p>I have a large dataset of numpy integers which I want to analyze with a GPU. The dataset is too large to fit into main memory on the GPU so I am trying to serialize them into a TFRecord and then use the API to stream the record for processing. The below code is example code: it wants to create some fake data, serial...
<p>Instead of </p> <pre><code>sess.run(iterator.initializer) while True: try: sess.run(next_element) fil,m,n = (next_element[0],next_element[1],next_element[2]) with sess.as_default(): print("fil.shape: ",fil.eval().shape) print("M: ",m.eval()) print("N: ...
745
tenserflow
How to make certain training samples more important in keras tenserflow?
https://stackoverflow.com/questions/69411841/how-to-make-certain-training-samples-more-important-in-keras-tenserflow
<p>I have data that contains a boolean feature (X), Is there is any way to make the samples that contain x=1 more important than other samples?</p> <p>NB1: By <strong>make certain training samples more important</strong> I mean these samples can affect the model more than other samples. I've already read something simi...
<p>I assume that by &quot;more important&quot; you mean samples with x=1 will have a larger impact to the cost function than samples where x is not =1. There are two parameters in model.fit that may enable you to do this, class_weight or sample_weight. From the documentation located <a href="https://www.tensorflow.org/...
746
tenserflow
Tensorflow Build error
https://stackoverflow.com/questions/42694991/tensorflow-build-error
<p>Hey I am new to Tenserflow, I got the tenserflow code from git (<a href="https://github.com/tensorflow/serving" rel="nofollow noreferrer">https://github.com/tensorflow/serving</a>) and when i tried to build it-using the steps in the documentation-I was getting this error:</p> <blockquote> <p>ERROR: com.google.d...
<p>This is probably because you have not cloned recursively (<code>git clone --recurse-submodules https://github.com/tensorflow/serving</code>) so TensorFlow does not get cloned as a submodule and Bazel cannot find TensorFlow itself.</p> <p>See <a href="https://github.com/tensorflow/serving/blob/master/tensorflow_serv...
747
tenserflow
import tensorflow as tf error occur in Anaconda Navigator
https://stackoverflow.com/questions/57913519/import-tensorflow-as-tf-error-occur-in-anaconda-navigator
<p>while importing tenserflow module in anaconda notebook I'm facing this error numpy.core.multiarray failed to import</p>
<p>Welcome to StackOverflow. Please consider <a href="https://stackoverflow.com/help/how-to-ask">reviewing "How do i ask a good question" guidelines</a> to provide more context. </p> <p>With your question, it is likely you have an older version of numpy installed in Anaconda through pip. Try using anaconda <a href="h...
748
tenserflow
How to Implement a tenserflow models prediction in a react native app page
https://stackoverflow.com/questions/77991441/how-to-implement-a-tenserflow-models-prediction-in-a-react-native-app-page
<p>I was working on my app, and was trying to figure out how to get my model to output a result in my react native app.</p> <p>In the app there is a page which prompts the user to take a photo, and from that image the model is supposed to print out the result on the next page after the user presses the button. I was ha...
749
tenserflow
No module named tensorflow.contrib.learn
https://stackoverflow.com/questions/41054895/no-module-named-tensorflow-contrib-learn
<p>I have tried installing tenserflow in my ubuntu os but i get error as no module what may be the problem !! </p> <p>My code :</p> <pre><code>import tensorflow.contrib.learn as learn from sklearn import datasets, metrics iris = datasets.load_iris() feature_columns = learn.infer_real_valued_columns_from_input(iris.d...
<p>In order to use <code>import tensorflow.contrib.learn as learn</code> this library use Tensorflow 1.15 version. install Tensorflow 1.15 using</p> <pre><code>pip install tensorflow==1.15 </code></pre>
750
tenserflow
Why does my model which uses Tenserflow and Keras GPU OOM error?
https://stackoverflow.com/questions/67813249/why-does-my-model-which-uses-tenserflow-and-keras-gpu-oom-error
<p>I am trying to run my model but i am running intro an error</p> <pre><code>2021-06-03 01:20:42.015864: W tensorflow/core/common_runtime/bfc_allocator.cc:467] **************************************************************************__________________________ 2021-06-03 01:20:42.015984: W tensorflow/core/framework/op...
<p>This error is Out Of Memory. Try to reduce the value of <code>batch_size</code>.</p>
751
tenserflow
How to resolve error in tenserflow installation caused by other packages version
https://stackoverflow.com/questions/64650802/how-to-resolve-error-in-tenserflow-installation-caused-by-other-packages-version
<p>I executed the command <code>pip install tensorflow</code> . But the installation is giving me following error. Below is the part of log</p> <pre><code>ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflic...
752
tenserflow
Train Object Detection Module Using Tensorflow
https://stackoverflow.com/questions/64035274/train-object-detection-module-using-tensorflow
<p>When I am executing the following command to train model using tenserflow, I got below errors.</p> <p><strong>Command</strong> :</p> <pre><code>python legacy/train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config </code></pre> <p><strong>Errors</strong> :</p...
<p>Probably <em>tf-slim</em> package is not installed in your python environment. Try running below command in the conda prompt</p> <pre><code>pip install tf-slim </code></pre>
753
tenserflow
Unknown image file format. One of JPEG, PNG, GIF, BMP required. [[{{node DecodeJpeg}}]] [Op:IteratorGetNext]
https://stackoverflow.com/questions/72760437/unknown-image-file-format-one-of-jpeg-png-gif-bmp-required-node-decodej
<p>heres the code:</p> <pre><code>encode_train = sorted(set(img_name_vector)) image_dataset = tf.data.Dataset.from_tensor_slices(encode_train) image_dataset = image_dataset.map(load_image, num_parallel_calls=tf.data.experimental.AUTOTUNE).batch(64) %%time for img, path in tqdm(image_dataset): batch_features = image_...
754
tenserflow
pytorch equivalent of Conv2D in tenserflow with stride of 2 and padding of (1,1)
https://stackoverflow.com/questions/71979310/pytorch-equivalent-of-conv2d-in-tenserflow-with-stride-of-2-and-padding-of-1-1
<p>I have <code>conv1 = nn.Conv2d(3, 16, 3,stride= 2, padding = 1, bias=True, groups=1)</code> . i need its corresponding api in <code>tf.keras.layers.Conv2D</code>.</p> <p>Can anyone help me out</p> <p>PS : Here i have a stride of <code>2</code></p>
<p>I have found the solution , hope this might be help full to others as well . As it was difficult to match <code>padding</code> in <code>torch</code> and <code>padding</code> in <code>keras</code> with <code>stride = 2</code></p> <pre><code>X = Input(shape = (10,10,3)) X1 = ZeroPadding2D(padding=(1,1), input_shape=(...
755
tenserflow
TensorFlow Net disable log information
https://stackoverflow.com/questions/74144000/tensorflow-net-disable-log-information
<p>How can I disable tenserflow information output in the console Tried changing Environment &quot;TF_CPP_MIN_LOG_LEVEL&quot; to 3 After looking at the answers on the Internet, I found only Python</p> <pre><code>2022-10-20 22:31:27.972310: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x22ca2648990 init...
<p>We can disable debugging information by using TF_CPP_MIN_LOG_LEVEL environment variable. It can be set before importing TensorFlow.</p> <pre><code>import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' import tensorflow as tf </code></pre> <p>Or manually set this environment variable before running Python script.</p> <p...
756
tenserflow
Firebase Cloud Function: Error loading TensorFlow model - tf.node.loadLayersModel not a function
https://stackoverflow.com/questions/79063388/firebase-cloud-function-error-loading-tensorflow-model-tf-node-loadlayersmode
<p>In firebase cloud function I'm trying to run a tenserflow model. But I keep getting the error: tf.node.loadLayersModel is not a function. Does anyone know what I might do wrong?</p> <pre><code>exports.runPredictionOnUpload = functions.firestore .document('modeltest/{docId}') .onCreate(async (snap, context) =...
757
tenserflow
What does &quot;dest_directory = FLAGS.model_dir&quot; mean?
https://stackoverflow.com/questions/47959726/what-does-dest-directory-flags-model-dir-mean
<p>I am trying to understand TenserFlow image classification. Got following <a href="https://github.com/shivakrishna9/tensorflow-retrain" rel="nofollow noreferrer">code</a> from GitHub, starts from 298 line in "retrain.py" script.</p> <pre><code>dest_directory = FLAGS.model_dir if not os.path.exists(dest_directory): o...
<p><code>FLAGS</code> holds parsed command line arguments. This script uses <a href="https://docs.python.org/3/library/argparse.html" rel="nofollow noreferrer"><code>argparse</code></a> library, but the style is inherited from <a href="/questions/tagged/gflags" class="post-tag" title="show questions tagged &#39;gflags&...
758
tenserflow
How to feed data for Tensorflow for multiple inputs for tpu?
https://stackoverflow.com/questions/55750998/how-to-feed-data-for-tensorflow-for-multiple-inputs-for-tpu
<p>I am trying to feed data for multiple inputs (2 inputs) for Keras (Tenserflow) for TPU training, but I get this error:</p> <pre><code>ValueError: The dataset returned a non-Tensor type ((&lt;class 'tensorflow.python.framework.ops.Tensor'&gt;, &lt;class 'tensorflow.python.framework.ops.Tensor'&gt;)) at index 0...
759
tenserflow
Tensorflow error script
https://stackoverflow.com/questions/51573503/tensorflow-error-script
<p>Here is my file:</p> <p>vim hello.py</p> <pre><code>from sklearn.preprocessing import PolynomialFeatures from sklearn import linear_model X = [[0.44, 0.68], [0.99, 0.23]] vector = [109.85, 155.72] predict= [0.49, 0.18] poly = PolynomialFeatures(degree=2) X_ = poly.fit_transform(X) predict_ = poly.fit_transform(p...
<p>In Python3, <code>print</code> needs parentheses to take in arguments: </p> <p><code>print(clf.predict(predict_))</code></p>
760
tenserflow
Is there any way to use sklearn complex model in android
https://stackoverflow.com/questions/71586009/is-there-any-way-to-use-sklearn-complex-model-in-android
<p>I searched alot but not found how to use model of sklearn in android .Yes simple model like find possibilities we can convert it into json and then can use via api in android but when we deal with live videos then what??</p> <p>And also my second doubt is &quot; can we use sklearn and tenserflow both in one model? &...
761
tenserflow
I am doing docker Jupyter deep learning course and ran in to a problem with importing keras libraries and packages
https://stackoverflow.com/questions/64384038/i-am-doing-docker-jupyter-deep-learning-course-and-ran-in-to-a-problem-with-impo
<p><a href="https://i.sstatic.net/aCqu6.png" rel="nofollow noreferrer">I tried running this command but i get erros that i dont have tenserflow 2.2 or higher. But I checked and I have the correct version of tenserflow. I also did pip3 install keras command </a> I know for a fact that all of the code is correct because ...
<p>just install tensorflow as requested in the last line of the error message: <code>pip install tensorflow</code>. It is needed as backend for Keras.</p> <p>Also, since keras is part of tensorflow now, I recommend to write imports as <code>from tensorflow.keras.[submodule name] import </code> instead of <code>from ker...
762
tenserflow
TensorFlow Android Camera Demo
https://stackoverflow.com/questions/40498899/tensorflow-android-camera-demo
<p>I have a questions about <a href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android/" rel="nofollow noreferrer">TensorFlow Android Camera Demo</a>, first of all, to start work with this demo I should download (clone) in my laptop all <a href="https://github.com/tensorflow/tensorflow" r...
<p>You have to first download the source from our <a href="https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#installing-from-sources" rel="nofollow noreferrer">repo</a>. Then follow the additional instructions for the <a href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/an...
763
tenserflow
How to resolve &#39;ImportError: /lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.29&#39; not found &#39; in raspberry pi Bullseye
https://stackoverflow.com/questions/76521316/how-to-resolve-importerror-lib-arm-linux-gnueabihf-libstdc-so-6-version-g
<p>Hi I'm trying to test tenserflow video classification tutorial. Here is the <a href="https://github.com/tensorflow/examples/tree/master/lite/examples/video_classification/raspberry_pi" rel="nofollow noreferrer">link</a>. After all the dependancies installation, I got issue <a href="https://i.sstatic.net/5RBpq.png" r...
<h2>TL;DR</h2> <p>Downgrade the pip package that requires this very GLIBCXX_3.4.29</p> <h2>Longer answer</h2> <p>Hi, I bumped into the same issue, although it was with image classification from the <code>examples</code> git repo (and not video classification in your case). In my stack trace, it stated that <code>tflit...
764
tenserflow
module &#39;tensorflow&#39; has no attribute &#39;merge_summary&#39; error
https://stackoverflow.com/questions/58207780/module-tensorflow-has-no-attribute-merge-summary-error
<p>Long story short I have this problem where when I run the code it says that the module I use Tensorflow has no attribute 'merge_summary' The thing is that I don't even use merge_summary.</p> <p>I have tried to uninstall tenserflow and it didn't work.</p> <pre class="lang-py prettyprint-override"><code>import nltk ...
<p>You can also try <strong>tf.compat.v1.summary.merge_all</strong> as merge_summary is deprecated.</p>
765
tenserflow
I have a NVIDIA Quadro 2000 graphic card, and I want to install TensorFlow. Will it work?
https://stackoverflow.com/questions/60108403/i-have-a-nvidia-quadro-2000-graphic-card-and-i-want-to-install-tensorflow-will
<p>I know Quadro 2000 is CUDA 2.1. My PC specs as follows:</p> <ul> <li>Quadro 2000 with 16GB RAM.</li> <li>Xeon(R) CPU W3520 @2.67GHz 2.66GHz</li> <li>Windows 10Pro. </li> </ul> <p>I want to use <strong>Tenserflow</strong> for Machine Learning, and Deep Learning.</p> <p>Let me know a little in-depth, as I am a b...
<p>Your system is eligible to use TensorFlow but not with GPU because that requires GPU a having compute capability more than 3.0, and your GPU is only a compute capability 2.1 device.</p> <p>You can read more about it <a href="https://github.com/tensorflow/tensorflow/issues/25" rel="nofollow noreferrer">here</a>.</p...
766
tenserflow
How to use BigBirdModel to create a neural network in Python?
https://stackoverflow.com/questions/67942218/how-to-use-bigbirdmodel-to-create-a-neural-network-in-python
<p>I am trying to create a network with tenserflow and BigBird.</p> <pre><code>from transformers import BigBirdModel import tensorflow as tf classic_model = BigBirdModel.from_pretrained('google/bigbird-roberta-base') input_ids = tf.keras.layers.Input(shape=(LEN, ), dtype='int64', name='input_ids') outputs = classic_m...
767
tenserflow
tf.saved_model.simple_save fail when converting from Keras model
https://stackoverflow.com/questions/59826281/tf-saved-model-simple-save-fail-when-converting-from-keras-model
<p>I want to convert Keras saved model to saved_model which can be using with Tenserflow serving</p> <p>I create model using pretrained model</p> <pre><code>feature_extractor_url = "https://tfhub.dev/google/tf2-preview/inception_v3/feature_vector/4" feature_extractor_layer = hub.KerasLayer(feature_extractor_url, inpu...
<p>I think I can fix the issue by adding <code>sess.run(tf.global_variables_initializer())</code> after load model from file</p>
768
tenserflow
Mask RCNN uses CPU instead of GPU
https://stackoverflow.com/questions/55211277/mask-rcnn-uses-cpu-instead-of-gpu
<p>I'm using the Mask RCNN library which is based on tenserflow and I can't seem to get it to run on my GPU (1080TI). The inference time is 4-5 seconds, during which I see a usage spike on my cpu but not my gpu. Any possible fixes for this?</p>
<p>It is either because that GPU_COUNT is set to 0 in <code>config.py</code> or you don't have <code>tensorflow-gpu</code> installed (which is required for tensorflow to run on GPU)</p>
769
tenserflow
I&#39;m pca with Deep neural network using TenserFlow with MNISt database, getting errors with shape of the data
https://stackoverflow.com/questions/53464139/im-pca-with-deep-neural-network-using-tenserflow-with-mnist-database-getting-e
<p>I'm trying to train the mnist database with the neural network after applying PCA. and I keep getting errors because of the data shape after applying the PCA. I'm not sure how to fit everything together. and how to go through the whole database, not just a small patch.</p> <p>here is my code:</p> <pre><code> &l...
<p>First of all, I´d recommend to fit PCA only for train set since you may get different PCA components for train and test. So the easiest fix is to change the following piece of code:</p> <pre><code>percent=600 pca=PCA(percent) train_x=pca.fit_transform(train_x) test_x=pca.fit_transform(test_x) </code></pre> <p>to</...
770
tenserflow
Image classification using ResNet-50
https://stackoverflow.com/questions/60397094/image-classification-using-resnet-50
<p>I try to train ResNet 50 for Image classification using this code: <a href="https://github.com/mlperf/training/blob/master/image_classification/tensorflow/official/resnet/imagenet_main.py" rel="nofollow noreferrer">https://github.com/mlperf/training/blob/master/image_classification/tensorflow/official/resnet/imagene...
<p>Your error message <code>IndexError: list index out of range</code> suggests that the list <code>argv</code> has length &lt; 2 (since index 1 is already out of bounds).</p> <p><code>sys.argv</code> contains the list of <em>argument values</em> that you pass on the command line. The first element, <code>argv[0]</cod...
771
tenserflow
Tensorflow error : Tensor.graph is meaningless when eager execution is enabled
https://stackoverflow.com/questions/66599444/tensorflow-error-tensor-graph-is-meaningless-when-eager-execution-is-enabled
<p>now I'm studying about tensorflow with jupyter notebook.</p> <p>But, I have a problem.</p> <p>my code like this!</p> <pre><code>sess = tf.compat.v1.Session() print(&quot;sess.run(node1, node2): &quot;, sess.run([node1, node2])) print(&quot;sess.run(node3): &quot;, sess.run(node3)) </code></pre> <p>error occur like ...
<p>You can disable eager-execution.</p> <pre><code>import tensorflow as tf tf.compat.v1.disable_eager_execution() </code></pre>
772
tenserflow
I m using Tenserflow 1.x by google colab but why i m getting error in that
https://stackoverflow.com/questions/63653898/i-m-using-tenserflow-1-x-by-google-colab-but-why-i-m-getting-error-in-that
<p>Code:</p> <pre><code>weights1 = tf.get_variable(&quot;weights1&quot;,shape=[12,80],initializer = tf.contrib.layers.xavier_initializer()) biases1 = tf.get_variable(&quot;biases1&quot;,shape = [80],initializer = tf.zeros_initializer) layer1out = tf.nn.relu(tf.matmul(X,weights1)+biases1) weights2 = tf.get_variable(&qu...
773
tenserflow
loading pretrained (CNN) model from .ckpt file using Pytorch
https://stackoverflow.com/questions/59023336/loading-pretrained-cnn-model-from-ckpt-file-using-pytorch
<p>I am using Pytorch for image classification. I am looking for CNN models pretrained on a dataset other than ImageNet, I have found a link to a ".ckpt" file. I also found tutorials on loading this file with Tenserflow, but not using pytorch. How can I load pretrained model using Pytorch from ".ckpt" file ? </p>
<p>I agree with @jodag that in general, PyTorch and Tensorflow are not interoperable. There are some special cases in which you may be able to do this. For example, HuggingFace provides support for converting the <a href="https://huggingface.co/transformers/converting_tensorflow_models.html" rel="nofollow noreferrer">t...
774
tenserflow
How to run Tensorflow GPU in Pycharm?
https://stackoverflow.com/questions/55549257/how-to-run-tensorflow-gpu-in-pycharm
<p>I want to run Tensorflow GPU in Pycharm on Linux Mint. </p> <p>I tried some guides like these</p> <p><a href="https://medium.com/@p.venkata.kishore/install-anaconda-tenserflow-gpu-keras-and-pycharm-on-windows-10-6bfb39630e4e" rel="nofollow noreferrer">https://medium.com/@p.venkata.kishore/install-anaconda-tenserfl...
<p>First Make sure CUDA and CuDNN has been installed successfully and Configuration should be verified.</p> <p>CUDA driver version should be sufficient for CUDA runtime version.</p> <p>Once done, Open PyCharm</p> <blockquote> <p><strong>Goto File-&gt;Settings-&gt; Project Interpreter</strong></p> </blockquote> <p>Selec...
775
tenserflow
Looking for input on an accuracy rate that is different than the exact deep learning compiled code
https://stackoverflow.com/questions/54318167/looking-for-input-on-an-accuracy-rate-that-is-different-than-the-exact-deep-lear
<p>I just began my Deep learning journey with Keras along with Tenserflow. I followed a tutorial that used a feed forward model on MNIST dataset. The strange part is that I used the same complied code, yet, I got a higher accuracy rate than the exact same code. I'm looking to understand why or how can this happen? </p>...
776
tenserflow
Where can I find more information about the tests made to verify the functionality of the Tenserflow Object Detection API
https://stackoverflow.com/questions/49954591/where-can-i-find-more-information-about-the-tests-made-to-verify-the-functionali
<p>I'm in a group project in school and we are currently using the <a href="https://github.com/tensorflow/models/tree/master/research/object_detection" rel="nofollow noreferrer">tensorflow object detection API</a>. The object detection works great but we are very interested in how the developers of this API have tested...
<p>Yes, the API is well tested. </p> <p>You can find the tests of each module in a python file at the same level and with the same name + the suffix "_test"</p> <p>As an example the module:</p> <p><a href="https://github.com/tensorflow/models/blob/master/research/object_detection/model_lib.py" rel="nofollow noreferr...
777
tenserflow
How to pickle weakref in Python Tensorflow-Keras?
https://stackoverflow.com/questions/67661244/how-to-pickle-weakref-in-python-tensorflow-keras
<p>I have written a voice recognition python , i have used tenserflow keras model.</p> <p>When i am giving the input to my model after running for 200 Epoch the exception raises, i tried to solve but its not working.</p> <p>I am getting this error can't pickle weakref objects.</p> <p>Exception Trace</p> <pre><code>Exce...
<p>I had the same issue with saving a Keras model and all of these mentioned methods such as <code>pickle</code>, <code>joblib</code> or even <code>model.save('filename')</code> didn't work. Finally, I got through this by calling directly the <code>save_model</code> method as bellow:</p> <pre><code>import tensorflow as...
778
tenserflow
Tensorflow build fails
https://stackoverflow.com/questions/64517692/tensorflow-build-fails
<p>I used this command:</p> <pre class="lang-sh prettyprint-override"><code>bazel test --config opt //tensorflow/tools/lib_package:libtensorflow_test </code></pre> <p>but I get this error:</p> <blockquote> <p>ERROR: C:/tenserflow/tensorflow-r1.14/tensorflow/tools/lib_package/BUILD:138:1: Executing genrule //tensorflow/...
779
tenserflow
Effective matrix slicing with numpy
https://stackoverflow.com/questions/53903938/effective-matrix-slicing-with-numpy
<p>I am trying to multiply sub-matrix on a sub-vector. It seems that such multiplication should be faster that multiplication of a whole matrix on a whole vector, but time measurements say opposite:</p> <pre><code>B = np.random.randn(26200, 2000) h = np.random.randn(2000) %time z = B @ h CPU times: user 56 ms, sys: 4 ...
<p>It's a problem of memory layout and time access. By default, <a href="https://docs.scipy.org/doc/numpy-1.15.0/reference/arrays.ndarray.html#internal-memory-layout-of-an-ndarray" rel="nofollow noreferrer">arrays are stored line by line like in C </a> (<code>order='C')</code>. You can store your data column by column ...
780
tenserflow
Getting same probability values for running the same code many times in prediction of images
https://stackoverflow.com/questions/57250281/getting-same-probability-values-for-running-the-same-code-many-times-in-predicti
<p>I tried in keras (using tenserflow backend) to classify and to predict the multi-class images. i built the model with accuracy 98 % and validation accuracy was 96 %. I predicted the probability of image classes and i got the probability values. When i am trying to predict the images with existing model (already buil...
781
tenserflow
Tensorflow not recognized even though it is installed
https://stackoverflow.com/questions/67361713/tensorflow-not-recognized-even-though-it-is-installed
<p>I am trying to run spot-rna on my windows pc. The computer is absolutely brand new and was opened today. I have installed python 3.6 and anaconda3. I also installed tensorflow in a virtual environment. Basically, I followed the installation steps (for gpu) given here: <a href="https://github.com/jaswindersingh2/SPOT...
782
tenserflow
How to load pretrained Tensorflow model from Google Cloud Storage into Datalab
https://stackoverflow.com/questions/58821870/how-to-load-pretrained-tensorflow-model-from-google-cloud-storage-into-datalab
<p>I have trained a model in Tensorflow (v2.0) Keras locally. I now need to upload this pretrained model into Google Datalab to make predictions on a large batch of data. Tenserflow version available on Datalab is 1.8 but I assume backward compatibility.</p> <p>I have uploaded the saved model (model.h5) onto Google Cl...
<p>I won't bet on backward compatibility. <a href="https://www.tensorflow.org/guide/versions" rel="nofollow noreferrer">Here</a> more details on it. </p> <p>In addition, your version is old. <a href="https://github.com/tensorflow/tensorflow/releases/tag/v1.8.0" rel="nofollow noreferrer">1.8</a> has been released in ap...
783
tenserflow
Is it possible to use API keys, from javascript, in a Python model and then use the model in Javascript?
https://stackoverflow.com/questions/56202889/is-it-possible-to-use-api-keys-from-javascript-in-a-python-model-and-then-use
<p>My plan is to use Python Machine Learning on an API key. By using that I will then use Tenserflow to translate that code into Javascript and start using my model there. </p> <p>I don't know if this is possible and I don't know if you even can use an API key from Javascript in Python. So I tried to find answers on t...
784
tenserflow
Pytorch - skip calculating features of pretrained models for every epoch
https://stackoverflow.com/questions/70236736/pytorch-skip-calculating-features-of-pretrained-models-for-every-epoch
<p>I am used to work with tenserflow - keras but now I am forced to start working with Pytorch for flexibility issues. However, I don't seem to find a pytorch code that is focused on training only the classifciation layer of a model. Is that not a common practice ? Now I have to wait out the calculation of the feature ...
<p>Assuming you already have the features ìn <code>features_x</code>, you can do something like this to create and train the model:</p> <pre><code># create a loader for the data dataset = torch.utils.data.TensorDataset(features_x, Y_train) loader = torch.utils.data.DataLoader(dataset, batch_size=16, shuffle=True) # de...
785
tenserflow
C++ Tensorflow Lite undefined referance
https://stackoverflow.com/questions/75234194/c-tensorflow-lite-undefined-referance
<p>I'm trying to build a project using Tensorflow Lite on my debian 11 machine, however it says I'm getting an undefined reference on some functions.</p> <p>Here is the code I'm trying to run:</p> <pre class="lang-cpp prettyprint-override"><code>// Works std::unique_ptr&lt;tflite::FlatBufferModel&gt; model = tf...
<p>The error suggests that you shouldn't build inside the source directory. To fix this:</p> <p>Create a separate build directory outside your source tree:</p> <pre class="lang-bash prettyprint-override"><code>mkdir build cd build </code></pre> <p>From this build directory, call cmake pointing to your source directory:...
786
tenserflow
Error while Installing tensorflow on aarch64
https://stackoverflow.com/questions/64641923/error-while-installing-tensorflow-on-aarch64
<p>I am new to Tensorflow and Python. I am trying to install the tenserflow on the aarch64 platform. I am getting the multiple errors while installing.</p> <pre><code>pip -V pip 20.2.4 python3 -V Python 3.7.8 </code></pre> <p>Trying to install</p> <pre><code>pip install tensorflow-2.3.0-cp37-none-linux_aarch64.whl </co...
<p>Most of the aarch64 related packages are getting resolved from <a href="https://www.piwheels.org/project/grpcio/#install" rel="nofollow noreferrer">https://www.piwheels.org/project/grpcio/#install</a>.</p> <p>Note:- Just rename the file to &lt;python_package_name&gt;----&lt;linux_aarch64&gt;.whl from or .</p>
787
tenserflow
ModuleNotFoundError: No module named &#39;tensorflow&#39; on Jupyter Notebook
https://stackoverflow.com/questions/70276937/modulenotfounderror-no-module-named-tensorflow-on-jupyter-notebook
<p>when I try to import keras on a Jupyter notebook I receive this error message: ModuleNotFoundError: No module named 'tensorflow'.</p> <p>I need to use keras to build an LSTM model fora project and am a beginner in python so I don't know how to get around this error. I have tried to install tenserflow and keras into ...
<p>You can add a cell at the beginning containing,</p> <pre><code> !pip install tensorflow </code></pre> <p>and run it before running to other cells</p>
788
tenserflow
Gradient of one layer w.r.t another layer when there is an input layer (and no value for the input)
https://stackoverflow.com/questions/73478858/gradient-of-one-layer-w-r-t-another-layer-when-there-is-an-input-layer-and-no-v
<p>I have a network written in tensorflow keras functional API. I'd like to use the gradient of one layer w.r.t to the previous layer as input for another layer. I tried gradient tape and tf.gradients and none of them worked. I get the following error:</p> <p><code>ValueError: tf.function-decorated function tried to cr...
<p>I would just inherit from tensorflow's <code>Layer</code> class and creating your own custom Layer. Also, it would probably be beneficial to put everything under one call so as to minimize the likelihood that there are disconnections in the graph.</p> <p><strong>Example</strong>:</p> <pre class="lang-py prettyprint-...
789
tenserflow
Ways to limit output of NN regression problem in certain limit(i.e. I want my NN to always predict output values only between -20 to +30)
https://stackoverflow.com/questions/56385199/ways-to-limit-output-of-nn-regression-problem-in-certain-limiti-e-i-want-my-nn
<p>I am training NN for the regression problem. So the output layer has a linear activation function. NN output is supposed to be between -20 to 30. My NN is performing good most of the time. However, sometimes it gives output more than 30 which is not desirable for my system. So does anyone know any activation functio...
<p>What you can do is to activate your last layer with a sigmoid, the result will be between 0 and 1 and then create a custom layer in order to get the desired range :</p> <pre><code>def get_range(input, maxx, minn): return (minn - maxx) * ((input - K.min(input, axis=1))/ (K.max(input, axis=1)*K.min(input, axis=1))...
790
tenserflow
Tensorflow is not running in windows 10
https://stackoverflow.com/questions/52428484/tensorflow-is-not-running-in-windows-10
<p>I'm new to tensorflow. I installed python and tensorflow. I'm getting below error after running my sample code. </p> <p>I have installed tensorflow by below command. I saw that the below command seems for mac, but I have used this command only to install tensorflow, it is successfully installed. I did not get link ...
<p>Firstly, For windows there isn't a direct link, you have to do it from source. Refer to this link for windows: <a href="https://www.tensorflow.org/install/source_windows" rel="nofollow noreferrer">https://www.tensorflow.org/install/source_windows</a></p> <p>Are you sure you have installed python correctly? I prefe...
791
tenserflow
model.fit_generator : Cannot convert a symbolic Tensor (args_2:0) to a numpy array
https://stackoverflow.com/questions/66477430/model-fit-generator-cannot-convert-a-symbolic-tensor-args-20-to-a-numpy-arr
<p>I an using tenserflow to build a model</p> <pre><code>inputs1 = Input(shape=(2048,)) fe1 = Dropout(0.5)(inputs1) fe2 = Dense(256, activation='relu')(fe1) inputs2 = Input(shape=(max_length,)) se1 = Embedding(vocab_size, embedding_dim, mask_zero=True)(inputs2) se2 = Dropout(0.5)(se1) se3 = LSTM(256)(se2) decoder1 =tf...
792
tenserflow
How to install additional dependencies in Tensorman
https://stackoverflow.com/questions/70721182/how-to-install-additional-dependencies-in-tensorman
<p>I am on popos 20.04 LTS and I want to use <a href="https://support.system76.com/articles/tensorman/" rel="nofollow noreferrer">Tensorman</a> for tenserflow/python. I'm new into docker and I want to install additional dependencies for example using default Image I can run jupyter notebook using these commands -</p> <...
<p>There are two ways to install dependencies.</p> <ol> <li>Create a custom image, install dependencies and save it.</li> <li>Use the <code>--root</code> tag to gain root access to the container, install dependencies and use them.</li> </ol> <h1>Build your own custom image</h1> <p>If you are working on a project and wa...
793
tenserflow
Tensorflow implementation for a simple logic
https://stackoverflow.com/questions/49154318/tensorflow-implementation-for-a-simple-logic
<p>I'm a new in Tensorflow. I want to implement an algorithm in Tensorflow that has a part of simple logic described bellow.</p> <p>I have a matrix (the size of matrix could be vary from a batch size). I need to replace all values in the matrix with zeros except maximum values in each row.</p> <p>I want to implement ...
<p>I think this is what you want. </p> <p>Ideally, we hope to mark the position with the largest element in the row with 1 and others with 0. Then we just need to multiply those two matrix element-wise. </p> <p>To get the position of the large element, we could use <code>tf.argmax</code> which help us find the index ...
794
tenserflow
Whenever I do pip3 freeze or any pip3 command in my mac terminal, it raises a syntax error
https://stackoverflow.com/questions/52434321/whenever-i-do-pip3-freeze-or-any-pip3-command-in-my-mac-terminal-it-raises-a-sy
<p>Usually, pip3 works normally, but after installing tenser flow using pip, for some reason pip is not working anymore. For example, I did <code>pip freeze</code> to get my packages, but it came up with this error.</p> <pre><code> Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Vers...
<p>It seems the cause of the problem is a Python 2.7 module somehow getting installed into python 3.6 folder. The guilty module is pygoogle. Uninstalling that may work. See:</p> <p><a href="https://www.pythonanywhere.com/forums/topic/12390/" rel="nofollow noreferrer">https://www.pythonanywhere.com/forums/topic/12390/<...
795
tenserflow
how can i fix windows c_api error with tensorflow.dll?
https://stackoverflow.com/questions/54426204/how-can-i-fix-windows-c-api-error-with-tensorflow-dll
<p>I tried to compile on windows c program with tenserflow c api and tenserflow.dll from <a href="https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip" rel="nofollow noreferrer">https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0...
<p>I guess it looks for tensorflow.so because you were using GCC tools on VS Code's WSL mode (or other IDEs). But in order to load DLL you need to have Visual Studio.</p> <p>Here's a simple process to run the Tensorflow for C demo:</p> <ol> <li>Create a new project in Visual Studio;</li> <li>Configure the project pro...
796
tenserflow
keras Sequential() crashes kernel
https://stackoverflow.com/questions/67168328/keras-sequential-crashes-kernel
<p>Just run a few lines with keras Sequential() crashes jupyter notebook kernel. Firstly it was GPU memory which reached all volume (no matter it is 3090 with 24 Gb). Then I took some precauses like</p> <pre><code>config = tf.compat.v1.ConfigProto() config.gpu_options.allow_growth = True session = tf.compat.v1.Session(...
<p>I tried to run .py file with same code in anaconda prompt and got 'Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found' so I uninstall CUDA 10.2 (which was the only way with 3080 card) and install 11.3 (which indeed was advised as the only choose with 3000x series at some place) wh...
797
tenserflow
tensorflow session.run() hangs while attempting to restore rnn model based on tutorial code
https://stackoverflow.com/questions/42433317/tensorflow-session-run-hangs-while-attempting-to-restore-rnn-model-based-on-tu
<p>I've been walking through the RNN code in TenserFlow tutorial: <a href="https://www.tensorflow.org/tutorials/recurrent" rel="nofollow noreferrer">https://www.tensorflow.org/tutorials/recurrent</a></p> <p>The original RNN code is here: <a href="https://github.com/tensorflow/models/blob/master/tutorials/rnn/ptb/ptb_w...
<p>Try installing Tensorflow from source. It is recommended because you can build the desired Tensorflow binary for the specific architecture (GPU, CUDA, cuDNN). </p> <p>This is even mentioned as one of the Best Practices for improving Tensorflow performance. Check the <a href="https://www.tensorflow.org/performance/...
798
tenserflow
Kotlin Multiplateform with TensorflowLite
https://stackoverflow.com/questions/60246182/kotlin-multiplateform-with-tensorflowlite
<p>Is there any way to develop project by using Kotlin Multiplateform and tensor flow lite model in the shared logic. Target is to use same tensor flow model with same kotlin code to retrieve data from it with android and iOS both. UI is desired to be developed separately with platform specific code. </p> <p>I have ex...
<p>Both iOS and Android have libraries for using TensorFlow but those libs are different libs, they are written for each platform independently (unlike TensorFlow C API which can be <a href="https://github.com/tensorflow/tensorflow/issues/35386" rel="nofollow noreferrer">built</a> for Android and iOS). So you won't be ...
799
keras
Keras input explanation: input_shape, units, batch_size, dim, etc
https://stackoverflow.com/questions/44747343/keras-input-explanation-input-shape-units-batch-size-dim-etc
<p>For any Keras layer (<code>Layer</code> class), can someone explain how to understand the difference between <code>input_shape</code>, <code>units</code>, <code>dim</code>, etc.? </p> <p>For example the doc says <code>units</code> specify the output shape of a layer. </p> <p>In the image of the neural net below <...
<h2>Units:</h2> <blockquote> <p>The amount of "neurons", or "cells", or whatever the layer has inside it. </p> </blockquote> <p>It's a property of each layer, and yes, it's related to the output shape (as we will see later). In your picture, except for the input layer, which is conceptually different from other l...
800
keras
Understanding Keras Long Short Term Memories (LSTMs)
https://stackoverflow.com/questions/38714959/understanding-keras-long-short-term-memories-lstms
<p>While trying to reconcile my understanding of LSTMs pointed out here in <a href="http://colah.github.io/posts/2015-08-Understanding-LSTMs/" rel="nofollow noreferrer">this post by Christopher Olah</a> implemented in Keras and following the <a href="http://machinelearningmastery.com/time-series-prediction-lstm-recurre...
<p>First of all, you choose great tutorials(<a href="http://colah.github.io/posts/2015-08-Understanding-LSTMs/">1</a>,<a href="http://karpathy.github.io/2015/05/21/rnn-effectiveness/">2</a>) to start.</p> <p><strong>What Time-step means</strong>: <code>Time-steps==3</code> in X.shape (Describing data shape) means ther...
801
keras
Can I run Keras model on gpu?
https://stackoverflow.com/questions/45662253/can-i-run-keras-model-on-gpu
<p>I'm running a Keras model, with a submission deadline of 36 hours, if I train my model on the cpu it will take approx 50 hours, is there a way to run Keras on gpu?</p> <p>I'm using Tensorflow backend and running it on my Jupyter notebook, without anaconda installed.</p>
<p>Yes you can run keras models on GPU. Few things you will have to check first.</p> <ol> <li>your system has GPU (Nvidia. As AMD doesn't work yet)</li> <li>You have installed the GPU version of tensorflow</li> <li>You have installed CUDA <a href="https://www.tensorflow.org/install/install_linux" rel="noreferrer">insta...
802
keras
Where do I call the BatchNormalization function in Keras?
https://stackoverflow.com/questions/34716454/where-do-i-call-the-batchnormalization-function-in-keras
<p>If I want to use the BatchNormalization function in Keras, then do I need to call it once only at the beginning?</p> <p>I read this documentation for it: <a href="http://keras.io/layers/normalization/">http://keras.io/layers/normalization/</a></p> <p>I don't see where I'm supposed to call it. Below is my code atte...
<p>As <a href="https://stackoverflow.com/questions/34716454/where-do-i-call-the-batchnormalization-function-in-keras/34751249#34751249">Pavel said</a>, Batch Normalization is just another layer, so you can use it as such to create your desired network architecture.</p> <p>The general use case is to use BN between the l...
803
keras
Many to one and many to many LSTM examples in Keras
https://stackoverflow.com/questions/43034960/many-to-one-and-many-to-many-lstm-examples-in-keras
<p>I try to understand LSTMs and how to build them with Keras. I found out, that there are principally the 4 modes to run a RNN (the 4 right ones in the picture)</p> <p><a href="https://i.sstatic.net/b4sus.jpg" rel="noreferrer"><img src="https://i.sstatic.net/b4sus.jpg" alt="enter image description here"></a> Image so...
<p>So:</p> <ol> <li><p><strong>One-to-one</strong>: you could use a <code>Dense</code> layer as you are not processing sequences:</p> <pre class="lang-py prettyprint-override"><code>model.add(Dense(output_size, input_shape=input_shape)) </code></pre> </li> <li><p><strong>One-to-many</strong>: this option is not suppor...
804
keras
How do I use the Tensorboard callback of Keras?
https://stackoverflow.com/questions/42112260/how-do-i-use-the-tensorboard-callback-of-keras
<p>I have built a neural network with Keras. I would visualize its data by Tensorboard, therefore I have utilized:</p> <pre class="lang-py prettyprint-override"><code>keras.callbacks.TensorBoard(log_dir='/Graph', histogram_freq=0, write_graph=True, write_images=True) </code></pre> <p>as ex...
<pre class="lang-py prettyprint-override"><code>keras.callbacks.TensorBoard(log_dir='./Graph', histogram_freq=0, write_graph=True, write_images=True) </code></pre> <p>This line creates a Callback Tensorboard object, you should capture that object and give it to the <code>fit</code> function of your model.</...
805
keras
What is the role of &quot;Flatten&quot; in Keras?
https://stackoverflow.com/questions/43237124/what-is-the-role-of-flatten-in-keras
<p>I am trying to understand the role of the <code>Flatten</code> function in Keras. Below is my code, which is a simple two-layer network. It takes in 2-dimensional data of shape (3, 2), and outputs 1-dimensional data of shape (1, 4):</p> <pre><code>model = Sequential() model.add(Dense(16, input_shape=(3, 2))) model....
<p>If you read the Keras documentation entry for <a href="https://keras.io/layers/core/#dense" rel="noreferrer"><code>Dense</code></a>, you will see that this call:</p> <pre><code>Dense(16, input_shape=(5,3)) </code></pre> <p>would result in a <code>Dense</code> network with 3 inputs and 16 outputs which would be appli...
806
keras
How to get reproducible results in keras
https://stackoverflow.com/questions/32419510/how-to-get-reproducible-results-in-keras
<p>I get different results (test accuracy) every time I run the <code>imdb_lstm.py</code> example from Keras framework (<a href="https://github.com/fchollet/keras/blob/master/examples/imdb_lstm.py">https://github.com/fchollet/keras/blob/master/examples/imdb_lstm.py</a>) The code contains <code>np.random.seed(1337)</cod...
<p>You can find the answer at the Keras docs: <a href="https://keras.io/getting-started/faq/#how-can-i-obtain-reproducible-results-using-keras-during-development" rel="noreferrer">https://keras.io/getting-started/faq/#how-can-i-obtain-reproducible-results-using-keras-during-development</a>.</p> <p>In short, to be abso...
807
keras
How do I print the model summary in PyTorch?
https://stackoverflow.com/questions/42480111/how-do-i-print-the-model-summary-in-pytorch
<p>How do I print the summary of a model in PyTorch like what <code>model.summary()</code> does in Keras:</p> <pre><code>Model Summary: ____________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ...
<p>While you will not get as detailed information about the model as in Keras' model.summary, simply printing the model will give you some idea about the different layers involved and their specifications.</p> <p>For instance:</p> <pre><code>from torchvision import models model = models.vgg16() print(model) </code></pr...
808
keras
Keras split train test set when using ImageDataGenerator
https://stackoverflow.com/questions/42443936/keras-split-train-test-set-when-using-imagedatagenerator
<p>I have a single directory which contains sub-folders (according to labels) of images. I want to split this data into train and test set while using ImageDataGenerator in Keras. Although model.fit() in keras has argument validation_split for specifying the split, I could not find the same for model.fit_generator(). H...
<p>Keras has now added Train / validation split from a single directory using ImageDataGenerator:</p> <pre><code>train_datagen = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, validation_split=0.2) # set validation split train_generator = train_datagen.flow_f...
809
keras
What is an Embedding in Keras?
https://stackoverflow.com/questions/38189713/what-is-an-embedding-in-keras
<p>Keras documentation isn't clear what this actually is. I understand we can use this to compress the input feature space into a smaller one. But how is this done from a neural design perspective? Is it an autoenocder, RBM?</p>
<p>As far as I know, the Embedding layer is a simple matrix multiplication that transforms words into their corresponding word embeddings.</p> <p>The weights of the Embedding layer are of the shape (vocabulary_size, embedding_dimension). For each training sample, its input are integers, which represent certain words. ...
810
keras
How to stack multiple lstm in keras?
https://stackoverflow.com/questions/40331510/how-to-stack-multiple-lstm-in-keras
<p>I am using deep learning library keras and trying to stack multiple LSTM with no luck. Below is my code</p> <pre><code>model = Sequential() model.add(LSTM(100,input_shape =(time_steps,vector_size))) model.add(LSTM(100)) </code></pre> <p>The above code returns error in the third line <code>Exception: Input 0 is inc...
<p>You need to add <code>return_sequences=True</code> to the first layer so that its output tensor has <code>ndim=3</code> (i.e. batch size, timesteps, hidden state).</p> <p>Please see the following example:</p> <pre><code># expected input data shape: (batch_size, timesteps, data_dim) model = Sequential() model.add(L...
811
keras
How to load a model from an HDF5 file in Keras?
https://stackoverflow.com/questions/35074549/how-to-load-a-model-from-an-hdf5-file-in-keras
<p>How to load a model from an HDF5 file in Keras?</p> <p>What I tried:</p> <pre><code>model = Sequential() model.add(Dense(64, input_dim=14, init='uniform')) model.add(LeakyReLU(alpha=0.3)) model.add(BatchNormalization(epsilon=1e-06, mode=0, momentum=0.9, weights=None)) model.add(Dropout(0.5)) model.add(Dense(64, ...
<p><code>load_weights</code> only sets the weights of your network. You still need to define its architecture before calling <code>load_weights</code>:</p> <pre><code>def create_model(): model = Sequential() model.add(Dense(64, input_dim=14, init='uniform')) model.add(LeakyReLU(alpha=0.3)) model.add(BatchN...
812
keras
Using Keras &amp; Tensorflow with AMD GPU
https://stackoverflow.com/questions/37892784/using-keras-tensorflow-with-amd-gpu
<p>I'm starting to learn Keras, which I believe is a layer on top of Tensorflow and Theano. However, I only have access to AMD GPUs such as the AMD R9 280X.</p> <p>How can I setup my Python environment such that I can make use of my AMD GPUs through Keras/Tensorflow support for OpenCL?</p> <p>I'm running on OSX.</p>...
<p>I'm writing an OpenCL 1.2 backend for Tensorflow at <a href="https://github.com/hughperkins/tensorflow-cl" rel="noreferrer">https://github.com/hughperkins/tensorflow-cl</a></p> <p>This fork of tensorflow for OpenCL has the following characteristics:</p> <ul> <li>it targets any/all OpenCL 1.2 devices. It doesnt ne...
813
keras
Can Keras with Tensorflow backend be forced to use CPU or GPU at will?
https://stackoverflow.com/questions/40690598/can-keras-with-tensorflow-backend-be-forced-to-use-cpu-or-gpu-at-will
<p>I have Keras installed with the Tensorflow backend and CUDA. I'd like to sometimes on demand force Keras to use CPU. Can this be done without say installing a separate CPU-only Tensorflow in a virtual environment? If so how? If the backend were Theano, the flags could be set, but I have not heard of Tensorflow f...
<p>If you want to force Keras to use CPU</p> <h2>Way 1</h2> <pre><code>import os os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" # see issue #152 os.environ["CUDA_VISIBLE_DEVICES"] = "" </code></pre> <p>before Keras / Tensorflow is imported.</p> <h2>Way 2</h2> <p>Run your script as</p> <pre><code>$ CUDA_VISIBLE_...
814
keras
&quot;Could not interpret optimizer identifier&quot; error in Keras
https://stackoverflow.com/questions/50056356/could-not-interpret-optimizer-identifier-error-in-keras
<p>I got this error when I tried to modify the learning rate parameter of SGD optimizer in Keras. Did I miss something in my code or my Keras was not installed properly?</p> <p>Here is my code:</p> <pre><code>from tensorflow.python.keras.models import Sequential from tensorflow.python.keras.layers import Dense, Flatten...
<p>The reason is you are using <code>tensorflow.python.keras</code> API for model and layers and <code>keras.optimizers</code> for SGD. They are two different Keras versions of TensorFlow and pure Keras. They could not work together. You have to change everything to one version. Then it should work.</p>
815
keras
Loading a trained Keras model and continue training
https://stackoverflow.com/questions/42666046/loading-a-trained-keras-model-and-continue-training
<p>I was wondering if it was possible to save a partly trained Keras model and continue the training after loading the model again.</p> <p>The reason for this is that I will have more training data in the future and I do not want to retrain the whole model again.</p> <p>The functions which I am using are:</p> <pre><cod...
<p>Actually - <code>model.save</code> saves all information need for restarting training in your case. The only thing which could be spoiled by reloading model is your optimizer state. To check that - try to <code>save</code> and reload model and train it on training data.</p>
816
keras
Keras: Difference between Kernel and Activity regularizers
https://stackoverflow.com/questions/44495698/keras-difference-between-kernel-and-activity-regularizers
<p>I have noticed that <em>weight_regularizer</em> is no more available in Keras and that, in its place, there are <em>activity</em> and <em>kernel</em> regularizer. I would like to know:</p> <ul> <li>What are the main differences between <em>kernel</em> and <em>activity</em> regularizers?</li> <li>Could I use <em>ac...
<p>The activity regularizer works as a function of the output of the net, and is mostly used to regularize hidden units, while weight_regularizer, as the name says, works on the weights (e.g. making them decay). Basically you can express the regularization loss as a function of the output (<code>activity_regularizer</c...
817
keras
How does Keras handle multilabel classification?
https://stackoverflow.com/questions/44164749/how-does-keras-handle-multilabel-classification
<p>I am unsure how to interpret the default behavior of Keras in the following situation:</p> <p>My Y (ground truth) was set up using scikit-learn's <code>MultilabelBinarizer</code>().</p> <p>Therefore, to give a random example, one row of my <code>y</code> column is one-hot encoded as such: <code>[0,0,0,1,0,1,0,0,0,...
<h1>In short</h1> <p>Don't use <code>softmax</code>.</p> <p>Use <code>sigmoid</code> for activation of your output layer.</p> <p>Use <code>binary_crossentropy</code> for loss function.</p> <p>Use <code>predict</code> for evaluation.</p> <h1>Why</h1> <p>In <code>softmax</code> when increasing score for one label, all ot...
818
keras
Convert Keras model to C++
https://stackoverflow.com/questions/36720498/convert-keras-model-to-c
<p>I am using Keras (with Theano) to train my CNN model. Does anyone has idea how can I use it in my C++ application? Does anyone tried something similar? I have idea to write some python code that will generate a c++ code with network functions - any suggestion on it?</p> <p>I found a similar question <a href="https:...
<p>To answer my own question and have a solution - I wrote a plain c++ solution called <a href="https://github.com/pplonski/keras2cpp" rel="noreferrer">keras2cpp</a> (its code available on github).</p> <p>In this solution you store network architecture (in json) and weights (in hdf5). Then you can dump a network to a ...
819
keras
&quot;AttributeError: &#39;str&#39; object has no attribute &#39;decode&#39; &quot; while Loading a Keras Saved Model
https://stackoverflow.com/questions/53740577/attributeerror-str-object-has-no-attribute-decode-while-loading-a-keras
<p>After Training, I saved Both Keras whole Model and Only Weights using </p> <pre><code>model.save_weights(MODEL_WEIGHTS) and model.save(MODEL_NAME) </code></pre> <p>Models and Weights were saved successfully and there was no error. I can successfully load the weights simply using model.load_weights and they are goo...
<p>For me the solution was downgrading the <code>h5py</code> package (in my case to 2.10.0), apparently putting back only Keras and Tensorflow to the correct versions was not enough.</p>
820
keras
keras ignoring values in $HOME/.keras/keras.json file
https://stackoverflow.com/questions/43054687/keras-ignoring-values-in-home-keras-keras-json-file
<p>I know the default backend for Keras has switched from Theano to TensorFlow, but with the dev version of Theano I can train on the GPU with OpenCL (I have an AMD card). </p> <p>However, when I import Keras, it only uses the TensorFlow backend <strong>even after I changed the values in the Keras configuration file</...
<p>Same issue here, system setup:</p> <ul> <li>Ubuntu 16.04</li> <li>Anaconda + Python 3.6</li> <li>Keras 2.0.2 </li> </ul> <p>The only way to change backend is to use KERAS_BACKEND environment variable. Json field is ignored.</p> <p>EDIT: The issue is Anaconda, open <code>anaconda3/envs/ENV-NAME/etc/conda/activate....
821
keras
How to export Keras .h5 to tensorflow .pb?
https://stackoverflow.com/questions/45466020/how-to-export-keras-h5-to-tensorflow-pb
<p>I have fine-tuned inception model with a new dataset and saved it as ".h5" model in Keras. now my goal is to run my model on android Tensorflow which accepts ".pb" extension only. question is that is there any library in Keras or tensorflow to do this conversion? I have seen this post so far : <a href="https://blog...
<p>Keras does not include by itself any means to export a TensorFlow graph as a protocol buffers file, but you can do it using regular TensorFlow utilities. <a href="https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc" rel="noreferrer">Here</a> is a blog post explaining...
822
keras
How to uninstall Keras?
https://stackoverflow.com/questions/41414489/how-to-uninstall-keras
<p>I have installed Keras using this command:</p> <pre><code>sudo pip install keras </code></pre> <p>It installed properly and worked fine until I tried to import application modules:</p> <pre><code>from keras.applications.vgg16 import VGG16 Using Theano backend. Couldn't import dot_parser, loading of dot files will...
<p>You can simply try from the following command:</p> <pre><code>pip uninstall keras </code></pre>
823
keras
keras: how to save the training history attribute of the history object
https://stackoverflow.com/questions/41061457/keras-how-to-save-the-training-history-attribute-of-the-history-object
<p>In Keras, we can return the output of <code>model.fit</code> to a history as follows:</p> <pre><code> history = model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=nb_epoch, validation_data=(X_test, y_test)) </code></pre> <p>Now, how to save ...
<p>What I use is the following:</p> <pre><code>with open('/trainHistoryDict', 'wb') as file_pi: pickle.dump(history.history, file_pi) </code></pre> <p>In this way I save the history as a dictionary in case I want to plot the loss or accuracy later on. Later, when you want to load the history again, you can use:</p>...
824
keras
What is the role of TimeDistributed layer in Keras?
https://stackoverflow.com/questions/47305618/what-is-the-role-of-timedistributed-layer-in-keras
<p>I am trying to grasp what TimeDistributed wrapper does in Keras.</p> <p>I get that TimeDistributed "applies a layer to every temporal slice of an input."</p> <p>But I did some experiment and got the results that I cannot understand.</p> <p>In short, in connection to LSTM layer, TimeDistributed and just Dense laye...
<p>In <code>keras</code> - while building a sequential model - usually the second dimension (one after sample dimension) - is related to a <code>time</code> dimension. This means that if for example, your data is <code>5-dim</code> with <code>(sample, time, width, length, channel)</code> you could apply a convolutional...
825
keras
Keras, How to get the output of each layer?
https://stackoverflow.com/questions/41711190/keras-how-to-get-the-output-of-each-layer
<p>I have trained a binary classification model with CNN, and here is my code</p> <pre><code>model = Sequential() model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1], border_mode='valid', input_shape=input_shape)) model.add(Activation('relu')) model.add(Co...
<p>You can easily get the outputs of any layer by using: <code>model.layers[index].output</code></p> <p>For all layers use this:</p> <pre><code>from keras import backend as K inp = model.input # input placeholder outputs = [layer.output for layer in model.layers] # ...
826
keras
How does keras handle multiple losses?
https://stackoverflow.com/questions/49404309/how-does-keras-handle-multiple-losses
<p>If I have something like:</p> <pre class="lang-python prettyprint-override"><code>model = Model(inputs = input, outputs = [y1,y2]) l1 = 0.5 l2 = 0.3 model.compile(loss = [loss1,loss2], loss_weights = [l1,l2], ...) </code></pre> <p>what does Keras do with the losses to obtain the final loss? Is it something like...
<p>From <a href="https://keras.io/models/model/" rel="noreferrer"><code>model</code> documentation</a>:</p> <blockquote> <p><strong>loss</strong>: String (name of objective function) or objective function. See losses. If the model has multiple outputs, you can use a different loss on each output by passing a diction...
827
keras
Get class labels from Keras functional model
https://stackoverflow.com/questions/38971293/get-class-labels-from-keras-functional-model
<p>I have a functional model in Keras (Resnet50 from repo examples). I trained it with <code>ImageDataGenerator</code> and <code>flow_from_directory</code> data and saved model to <code>.h5</code> file. When I call <code>model.predict</code> I get an array of class probabilities. But I want to associate them with class...
<pre><code>y_prob = model.predict(x) y_classes = y_prob.argmax(axis=-1) </code></pre> <p>As suggested <a href="https://github.com/fchollet/keras/issues/5961" rel="noreferrer">here</a>.</p>
828
keras
ImportError: No module named &#39;keras&#39;
https://stackoverflow.com/questions/45271344/importerror-no-module-named-keras
<p>So basically, I am fairly new to programming and using python. I am trying to build an ANN model for which I have to use Tensor flow, Theano and Keras library. I have Anaconda 4.4.1 with Python 3.5.2 on Windows 10 x64 and I have installed these libraries by following method.</p> <ol> <li>Create a new environment wi...
<p>Hi I have an solution try this if you are using <code>Anaconda-Navigator</code> </p> <p>go to <strong>Anaconda Environment</strong> and search <strong>keras package</strong> and then <strong>install</strong>.</p> <p><a href="https://i.sstatic.net/Od3L9.png" rel="noreferrer"><img src="https://i.sstatic.net/Od3L9.pn...
829
keras
Keras - Difference between categorical_accuracy and sparse_categorical_accuracy
https://stackoverflow.com/questions/44477489/keras-difference-between-categorical-accuracy-and-sparse-categorical-accuracy
<p>What is the difference between <code>categorical_accuracy</code> and <code>sparse_categorical_accuracy</code> in Keras? There is no hint in the <a href="https://keras.io/metrics/" rel="noreferrer">documentation for these metrics</a>, and by asking Dr. Google, I did not find answers for that either.</p> <p>The sourc...
<p>Looking at the <a href="https://github.com/fchollet/keras/blob/0bc8fac4463c68faa3b3c415c26eab02aa361fd5/keras/metrics.py#L24" rel="noreferrer">source</a> </p> <pre><code>def categorical_accuracy(y_true, y_pred): return K.cast(K.equal(K.argmax(y_true, axis=-1), K.argmax(y_pred, axis=-1)...
830
keras
Keras initializers outside Keras
https://stackoverflow.com/questions/46770721/keras-initializers-outside-keras
<p>I want to initialize a 4*11 matrix using glorot uniform in Keras, using following code:</p> <pre><code>import keras keras.initializers.glorot_uniform((4,11)) </code></pre> <p>I get this output :</p> <pre><code>&lt;keras.initializers.VarianceScaling at 0x7f9666fc48d0&gt; </code></pre> <p>How can I visualize the o...
<p>The <code>glorot_uniform()</code> creates a function, and later this function will be called with a shape. So you need:</p> <pre><code># from keras.initializers import * #(tf 1.x) from tensorflow.keras.initializers import * unif = glorot_uniform() #this returns a 'function(shape)' mat_as_tensor = unif((4,11)) #th...
831
keras
Keras Conv2D and input channels
https://stackoverflow.com/questions/43306323/keras-conv2d-and-input-channels
<p>The Keras layer documentation specifies the input and output sizes for convolutional layers: <a href="https://keras.io/layers/convolutional/" rel="noreferrer">https://keras.io/layers/convolutional/</a></p> <p>Input shape: <code>(samples, channels, rows, cols)</code></p> <p>Output shape: <code>(samples, filters, ne...
<p>It might be confusing that it is called <strong>Conv2D</strong> layer (it was to me, which is why I came looking for this answer), because as Nilesh Birari commented:</p> <blockquote> <p>I guess you are missing it's 3D kernel [width, height, depth]. So the result is summation across channels.</p> </blockquote> <...
832
keras
What is the difference between loss function and metric in Keras?
https://stackoverflow.com/questions/48280873/what-is-the-difference-between-loss-function-and-metric-in-keras
<p>It is not clear for me the difference between loss function and metrics in Keras. The documentation was not helpful for me.</p>
<p>The loss function is used to optimize your model. This is the function that will get minimized by the optimizer.</p> <p>A metric is used to judge the performance of your model. This is only for you to look at and has nothing to do with the optimization process.</p>
833