tensorflow

x and y can be no greater than 2-D, but have shapes (1,) and (1, 224, 224, 3)

给你一囗甜甜゛ 提交于 2021-01-28 11:11:44
问题 I am trying to visualize the prediction of VGG-16 for the cat image, Compute the top-5 scores (the 5 classes with the maximum probability), For each of these 5 scores, print the corresponding label and the corresponding probability. from keras.applications.vgg16 import preprocess_input from keras.preprocessing import image # load the image from cat class and resize it img = image.load_img('cat.jpg', target_size=(224, 224)) # convert to numpy array of (224, 224, 3) x = image.img_to_array(img)

How to wrap tensorflow graph with placeholder in keras

[亡魂溺海] 提交于 2021-01-28 11:09:41
问题 I have a tensorflow graph (stored in a protobuffer file) with placeholder operations as inputs. I want to wrap this graph as a keras layer or model. Here is an example: with tf.Graph().as_default() as gf: x = tf.placeholder(tf.float32, shape=(None, 123), name='x') c = tf.constant(100, dtype=tf.float32, name='C') y = tf.multiply(x, c, name='y') with tf.gfile.GFile("test_graph/y.pb", "wb") as f: raw = gf.as_graph_def().SerializeToString() f.write(raw) Load back as a tensorflow graph: persisted

Subsampling an unbalanced dataset in tensorflow

跟風遠走 提交于 2021-01-28 10:55:45
问题 Tensorflow beginner here. This is my first project and I am working with pre-defined estimators. I have an extremely unbalanced dataset where positive outcomes represent roughly 0.1% of the total data and I suspect this imbalance to considerably affect the performance of my model. As a first attempt to solve the issue, since I have tons of data, I would like to throw away most of my negatives in order to create a balanced dataset. I can see two ways of doing it: preprocess the data to keep

Keras Model - Get input in custom loss function

一曲冷凌霜 提交于 2021-01-28 10:15:55
问题 I am having trouble with Keras Custom loss function. I want to be able to access truth as a numpy array. Because it is a callback function, I think I am not in eager execution , which means I can't access it using the backend.get_value() function. i also tried different methods, but it always comes back to the fact that this 'Tensor' object doesn't exist. Do I need to create a session inside the custom loss function ? I am using Tensorflow 2.2, which is up to date. def custom_loss(y_true, y

Keras Model - Get input in custom loss function

走远了吗. 提交于 2021-01-28 10:12:04
问题 I am having trouble with Keras Custom loss function. I want to be able to access truth as a numpy array. Because it is a callback function, I think I am not in eager execution , which means I can't access it using the backend.get_value() function. i also tried different methods, but it always comes back to the fact that this 'Tensor' object doesn't exist. Do I need to create a session inside the custom loss function ? I am using Tensorflow 2.2, which is up to date. def custom_loss(y_true, y

Shearing image in tensorflow

寵の児 提交于 2021-01-28 09:26:07
问题 I am using tf.keras to build my network. And I am doing all the augmentation in tensor_wise level since my data in tfrecords file. Then I needed to do shearing and zca for augmentation but couldn't find a proper implementation in tensor flow. And I can't use the DataImageGenerator that did both operation I needed because as I said my data doesn't fit in memory and it is in tfrecord format. So all my augmentations process should be tesnorwise. @fchollet here suggested a way to use

Shearing image in tensorflow

主宰稳场 提交于 2021-01-28 09:25:02
问题 I am using tf.keras to build my network. And I am doing all the augmentation in tensor_wise level since my data in tfrecords file. Then I needed to do shearing and zca for augmentation but couldn't find a proper implementation in tensor flow. And I can't use the DataImageGenerator that did both operation I needed because as I said my data doesn't fit in memory and it is in tfrecord format. So all my augmentations process should be tesnorwise. @fchollet here suggested a way to use

Keras ValueError: No gradients provided for any variable

£可爱£侵袭症+ 提交于 2021-01-28 09:01:14
问题 I've read related threads but not been able to solve my problem. I'm currently trying to get my model to run in order to classify 5000 different events, which all currently fall under the same category (so my "labels" dataset consists of 5000 1s). I'm using one hot encoding for my labels data set: labels = np.loadtxt("/content/drive/My Drive/5000labels1.csv") from keras.utils import to_categorical labels=to_categorical(labels) # convert labels to one-hot encoding I then define my model like

Can't import tensorflow in PyCharm

白昼怎懂夜的黑 提交于 2021-01-28 09:00:28
问题 I'm trying to import tensorflow in PyCharm, however I get an error that the module is not found. I used pip install to install tensorflow. Also when I look at the interpreter in PyCharm it says I have pip version 9.0.1 and the latest is 10.0.1. I have upgraded to 10.0.1 using the pip commands, and when I run pip --version it says I got 10.0.1. I have tried both reinstalling pycharm and making new projects with no luck. 回答1: Go to Files -> Settings -> Project:projectname -> Project Interpreter

Converting saved_model.pb to model.tflite

旧街凉风 提交于 2021-01-28 08:48:43
问题 Tensorflow Version: 2.2.0 OS: Windows 10 I am trying to convert a saved_model.pb to a tflite file. Here is the code I am running: import tensorflow as tf # Convert converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir='C:\Data\TFOD\models\ssd_mobilenet_v2_quantized') tflite_model = converter.convert() fo = open("model.tflite", "wb") fo.write(tflite_model) fo.close This code gives an error while converting: File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages