the error is mentioned in the picture.
TypeError Traceback (most recent call last)
<ipython-input-200-8ea67f851d87> in <module>()
1 final_model = Sequential([
----> 2 Concatenate([image_model, caption_model], mode='concat', concat_axis=1),
3 Bidirectional(LSTM(256, return_sequences=False)),
4 Dense(vocab_size),
5 Activation('softmax')
You are using the Concatenate layer wrong. Change your code to the following:
final_model = Sequential([
Concatenate([image_model, caption_model], axis=1),
Bidirectional(LSTM(256, return_sequences=False))
Dense(vocab_size), 5 Activation('softmax'),
Activation('softmax')
])
Related
Im having problem by svm predict model
from sklearn.svm import SVC
svm_model = SVC(kernel='rbf', C=8, gamma=0.1)
svm_model.fit(X_train_std, y_train)
y_pred = svm_model.predict(X_test_std)
/usr/local/lib/python3.8/dist-packages/sklearn/utils/validation.py:993: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
y = column_or_1d(y, warn=True)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-53-398f1caaa8e8> in <module>
3 svm_model = SVC(kernel='rbf', C=8, gamma=0.1)
4
----> 5 svm_model.fit(X_train_std, y_train)
6
7 y_pred = svm_model.predict(X_test_std)
2 frames
/usr/local/lib/python3.8/dist-packages/sklearn/utils/multiclass.py in check_classification_targets(y)
195 "multilabel-sequences",
196 ]:
--> 197 raise ValueError("Unknown label type: %r" % y_type)
198
199
ValueError: Unknown label type: 'continuous'
I thought y type problem
train = pd.get_dummies(train, columns=['LSTAT'], drop_first=True)
So I use that but problem was disappeared
Somebody help me
how can I shape this to 4D in python-3.x
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-41-3ebb07a7b8c5> in <module>
----> 1 x_train = x_train.reshape((n_samples_train, 22, 1000, 1))
2 x_test = x_test.reshape((n_samples_test, 22, 1000, 1))
3
4 print(x_train.shape)
5 print(x_test.shape)
ValueError: cannot reshape array of size 662250 into shape (883,22,1000,1)
883x22x1000x1 = 18.326.000, which of course is different from 662.250. Ensure you reshape in a correct format.
This is the error I get on my program. anyone can say what is the problem of my code.
32 filters
input shape 100 rows 100 cols 15 patchsize
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-42-4fac16b2e337> in <module>
3 print('input shape', img_rows, 'rows', img_cols, 'cols', patch_size, 'patchsize')
4
----> 5 model.add(Convolution3D(
6 nb_filters[0],
7 kernel_dim1=1, # depth
TypeError: __init__() missing 1 required positional argument: 'kernel_size'
This is my code what is the problem I don't understand if you know the solution please suggest me thank you. i am using tf-2.3 python 3.7
model = Sequential()
print(nb_filters[0], 'filters')
print('input shape', img_rows, 'rows', img_cols, 'cols', patch_size, 'patchsize')
model.add(Convolution3D(
nb_filters[0],
kernel_dim1=1, # depth
kernel_dim2=nb_conv[0], # rows
kernel_dim3=nb_conv[1], # cols
input_shape=(1, img_rows, img_cols, patch_size),
activation='relu'
))
model.add(MaxPooling3D(pool_size=(1, nb_pool[0], nb_pool[0])))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(128, init='normal', activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(nb_classes,init='normal'))
model.add(Activation('softmax'))
#optimizer adam,sgd,RMSprop,Adagrad,Adadelta,Nadam,
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
I am converting my mnist cnn ML code to tf 2.0. codes were running well in tf 1.13
After switch to tf 2.0 and modified it, at the step of model fitting, an error occurred.
code
annealer = LearningRateScheduler(lambda x: 1e-3 * 0.95 ** x)
batch_size = 100
epochs = 30
history = model.fit_generator(datagen.flow(X_train,Y_train, batch_size=batch_size),
epochs = epochs,
validation_data = (X_val,Y_val),
verbose = 1,
steps_per_epoch=X_train.shape[0] // batch_size,
callbacks=[annealer])
error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-39-d1e7a6160362> in <module>()
7 verbose = 1,
8 steps_per_epoch=X_train.shape[0] // batch_size,
----> 9 callbacks=[annealer])
5 frames
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in get_session()
188 global _SESSION
189
--> 190 default_session = tf.get_default_session()
191
192 if default_session is not None:
AttributeError: module 'tensorflow' has no attribute 'get_default_session'
if I remove 'callback' or switch model.fit without callbacks option, everything runs well.
and I assume this is some incompatibility issue.
any suggestion how to implement callback right, so that I can do the variable lr?
thanks.
I am experimenting the Bidirectional wrapper in Keras, and a sample code is as follows.
T = 8
D = 2
M = 3
input_ = Input(shape=(T, D))
rnn = Bidirectional(LSTM(M, return_state=True, return_sequences=True))
#rnn = LSTM(M, return_state=True, return_sequences=True)
x = rnn(input_)
model = Model(inputs=input_, outputs=x)
X = np.random.randn(1,T,D)
o, h1, c1, h2, c2 = model.predict(X)
However, it gives an error
ValueError Traceback (most recent call last)
<ipython-input-82-53f1c7a28b54> in <module>()
19 print("c:", c1)
20
---> 21 lstm1()
<ipython-input-82-53f1c7a28b54> in lstm1()
8 rnn = Bidirectional(LSTM(M, return_state=True, return_sequences=True))
9 #rnn = LSTM(M, return_state=True, return_sequences=True)
---> 10 x = rnn(input_)
...
ValueError: Tried to convert 'tensor' to a tensor and failed. Error:
Shapes must be equal rank, but are 3 and 2
From merging shape 0 with other shapes. for 'bidirectional_26/ReverseV2_1
/packed' (op: 'Pack') with input shapes: [?,?,3], [?,3], [?,3].
If I remove the Bidirectional wrapper, i.e.
rnn = LSTM(M, return_state=True, return_sequences=True)
then it does not have a problem. Any advise would be greatly appreciated!