tensorflow

AttributeError: 'Tensor' object has no attribute '_keras_history' using CRF

牧云@^-^@ 提交于 2021-01-29 21:42:09
问题 I know there are a bunch of questions on this problem and I have read some of those but none of them worked for me. I am trying to build a model with the following architecture: The code is as follows: token_inputs = Input((32,), dtype=tf.int32, name='input_ids') mask_inputs = Input((32,), dtype=tf.int32, name='attention_mask') seg_inputs = Input((32,), dtype=tf.int32, name='token_type_ids') seq_out, _ = bert_model([token_inputs, mask_inputs, seg_inputs]) bd = Bidirectional(LSTM(units=50,

Using functional Api in tensorflow throws KeyError: 'input_1'

江枫思渺然 提交于 2021-01-29 21:33:15
问题 I'm trying to build a simple linear model using TensorFlow functional API. def create_model(): input1 = tf.keras.Input(shape=(30,)) hidden1 = tf.keras.layers.Dense(units = 12, activation='relu')(input1) hidden2 = tf.keras.layers.Dense(units = 6, activation='relu')(hidden1) output1 = tf.keras.layers.Dense(units = 2, activation='softmax')(hidden2) model = tf.keras.models.Model(inputs = input1, outputs = output1) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=[

Run Mask RCNN code and stuck at “Converting sparse IndexedSlices to a dense Tensor of unknown shape”

痴心易碎 提交于 2021-01-29 21:16:13
问题 I'm new to Python and Tensorflow Running Mask RCNN code from this tutorial and got stuck at " Converting sparse IndexedSlices to a dense Tensor of unknown shape. " Here's my configuration part of train.py shown as following import os import sys import json import datetime import numpy as np import skimage.draw import cv2 from mrcnn.visualize import display_instances import matplotlib.pyplot as plt # Root directory of the project ROOT_DIR = "" # Import Mask RCNN sys.path.append(ROOT_DIR) # To

How to change Sequential model to Custom Class model

霸气de小男生 提交于 2021-01-29 21:15:09
问题 I'm learning tensorflow 2.0 from its older versions. I found tensorflow model is changed Sequential-base from Class-base. But I want to use Class-base model because it is easy to read for me. I want to try translate : https://www.tensorflow.org/beta/tutorials/keras/basic_text_classification_with_tfhub embedding = 'https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1' hub_layer = hub.KerasLayer(embedding, input_shape=[], dtype=tf.string, trainable=True) # hub_layer(train_example_batch[:3]

AttributeError: 'Tensor' object has no attribute '_keras_history' using CRF

◇◆丶佛笑我妖孽 提交于 2021-01-29 19:58:30
问题 I know there are a bunch of questions on this problem and I have read some of those but none of them worked for me. I am trying to build a model with the following architecture: The code is as follows: token_inputs = Input((32,), dtype=tf.int32, name='input_ids') mask_inputs = Input((32,), dtype=tf.int32, name='attention_mask') seg_inputs = Input((32,), dtype=tf.int32, name='token_type_ids') seq_out, _ = bert_model([token_inputs, mask_inputs, seg_inputs]) bd = Bidirectional(LSTM(units=50,

I got value error that image has no shape while converting image to tensor for performing neural style transfer

岁酱吖の 提交于 2021-01-29 19:26:33
问题 I am using tensorflow_hub modules to perform neural style transfer and I get the error "'images' contains no shape". I don't understand where I made a mistake. This is my code: import tensorflow_hub as hub import tensorflow as tf import numpy as np import matplotlib.pyplot as plt content_path = r'C:\Users\Sriram\Desktop\efil.jpg' style_path = r'C:\Users\Sriram\Desktop\download1.jfif' content_image = plt.imread(content_path) style_image = plt.imread(style_path) plt.subplot(1, 2, 1) plt.title(

InvalidArgumentError: 2 root error(s) found. (0) Invalid argument: Incompatible shapes: [4,3] vs. [4,4]

六月ゝ 毕业季﹏ 提交于 2021-01-29 18:54:42
问题 I am facing below error when trying to train a multi-class classification model ( 4 classes) for Image dataset. Even though my output tensor is of shape 4 I am facing below issue. Please let me know how to fix this issue. Epoch 1/10 --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) <ipython-input-30-01c6f78f4d4f> in <module> 4 epochs=epochs, 5 validation_data=val_data_gen, ----> 6 validation_steps=total_val //

predict result for single record using keras model predict

笑着哭i 提交于 2021-01-29 18:51:11
问题 I have created model using Keras. Here is the associated code. - https://github.com/CVxTz/ECG_Heartbeat_Classification/blob/master/code/baseline_mitbih.py I could run it and get model accuracy. IT works as expect for train and test data. Now I Want to test with out sample record and get prediction result. How do I do this? My code - df_train = pd.read_csv("mitbih_train.csv", header=None) df_train = df_train.sample(frac=1) df_test = pd.read_csv("mitbih_test.csv", header=None) Y = np.array(df

Create SavedModel for BERT

怎甘沉沦 提交于 2021-01-29 18:20:39
问题 I'm using this Colab for BERT model. In last cells in order to make predictions we have: def getPrediction(in_sentences): labels = ["Negative", "Positive"] input_examples = [run_classifier.InputExample(guid="", text_a = x, text_b = None, label = 0) for x in in_sentences] # here, "" is just a dummy label input_features = run_classifier.convert_examples_to_features(input_examples, label_list, MAX_SEQ_LENGTH, tokenizer) predict_input_fn = run_classifier.input_fn_builder(features=input_features,

How to save keras custom model with dynamic input shape in SaveModel format?

南楼画角 提交于 2021-01-29 18:11:31
问题 I have a custom model with dynamic input shape (flexible second dimension). I need to save it in SaveModel format. But it saves only one signature (the first used). When I try to use different signature after loading - I am getting an error: Python inputs incompatible with input_signature My code is as follows: seq_len = 2 batch_size = 3 import tensorflow as tf class CustomModule(tf.keras.Model): def __init__(self): super(CustomModule, self).__init__() self.v = tf.Variable(1.) #@tf.function