我当时正在做“Iris数据集上的模型验证”的作业。
我得到这个错误:“检查输入时出错:期望dense_input具有形状(135,),但得到具有形状(4,)的数组”。我如何克服这个问题?
我的代码是
from numpy.random import seed
seed(8)
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets, model_selection
from sklearn.model_selection import trai
当我试图在一个带有conv1d层的网络中计算Xw.r.tY的梯度时,我得到的消息是“来自维度3、0、C的无效索引”,进程就会停止。
最小工作实例:
import numpy as np
from tensorflow.python.keras import models
from tensorflow.python.keras import layers
from tensorflow.python.keras import backend as K
inp = layers.Input(shape=(10, 20,))
conv = layers.Conv1D(filters=10, k
我试图在Tensorflow中计算相同维的n张量的线性组合。标量系数为Tensorflow Variables。
由于tf.scalar_mul没有推广到将张量向量乘以标量向量,因此到目前为止,我使用了tf.gather,并在pythonfor循环中分别执行了每个乘法,然后将结果列表转换为一个张量,并将它们相加到零轴。就像这样:
coefficients = tf.Variable(tf.constant(initial_value, shape=[n]))
components = []
for i in range(n):
components.append(tf.scalar_m
根据Keras中的shared layers documentation,可以创建一个共享层,并使用不同的输入形状实例化它。它给出了一个Conv2D共享层的示例,如下所示: a = Input(shape=(32, 32, 3))
b = Input(shape=(64, 64, 3))
conv = Conv2D(16, (3, 3), padding='same')
conved_a = conv(a)
# Only one input so far, the following will work:
assert conv.input_shape == (None,
我尝试使用R进行音频分类,但我遇到了网络形状错误不兼容的问题。我创建了这两个函数,以便读取所有的wave文件并使用mel特性将它们转换成一个矩阵
audio = readWave(paste(outDir, '/', labels$filename[i], sep = ('') ))
audio = normalize(audio)
audio = crop(audio) #in order to have all signals of same size
return(melfcc(audio, sr = audio@samp.rate))
}
我正在尝试用Tensorflow重写下面的Python代码。但是,我在使用tf.map_fn迭代张量时遇到了问题。
这里depth是形状[batch_size,256,256]的张量,normal是形状[batch_size,256,256,3]的张量,scale是形状[batch_size,256,256]的张量。
for b in range(0,batch_size):
depth[b,:,:] = [scale[b,0,0] + (scale[b,0,1] - scale[b,0,0])* x for x in depth[b,:,:]]
normal[b,:,:,:]
我有一个tflite模型,期望输入形状为(1,1000,12)。为了测试它,我打算加载一个CSV文件并对其运行推理。下面是我的代码和我在运行它时得到的错误消息的相关部分。 我假设我在正确加载或读取CSV文件时犯了一个错误。我是Android的新手,在这件事上如果有任何帮助,我将非常感谢! val testModel = myModel.newInstance(context)
// Creates inputs for reference.
val inputFeature0 = TensorBuffer.createFixedSize(intArrayOf(1, 1000, 12), D
我有一个形状为[x, y]的张量,我想要减去平均值,然后逐行除以标准差(即我想对每一行做这件事)。在TensorFlow中执行此操作的最有效方法是什么?
当然,我可以按如下方式遍历各行:
new_tensor = [i - tf.reduce_mean(i) for i in old_tensor]
...to减去平均值,然后做一些类似的事情来找出标准差并除以它,但这是在TensorFlow中做这件事的最好方法吗?
在这里看到:
这是可复制的代码:
import numpy as np
import tensorflow as tf
points = np.random.random_sample((10,2))
tf_points = tf.constant(points)
slice = tf.slice(tf_points,[0,0],[4,-1])
print tf.subtract(tf_points,slice).get_shape() #This errors out because the dimensions are incorrect
tf_points_expanded = t
我正在运行,我已经遇到了一些与pathing等有关的错误。修复之后,我认为目前的主要错误是tensorflow。这个回购可能是在Tf1.x时完成的,现在随着Tf2的改变,我可能需要迁移所有的东西。
主要是,我得到了以下错误:
@ops.RegisterShape('ApproxMatch')
AttributeError: module 'tensorflow.python.framework.ops' has no attribute 'RegisterShape'
在:
import tensorflow as tf
from ten
我正在尝试使用数据库中其他列的np.where条件创建一个新列。
我的代码
df5['RiskSubType']=np.where(new_df['Snow_Risk']==1,(( ' Heavy Snow forecasted at ' +df5.LOCATION.mask(new_df.LOCATION=='',df5.LOCATION_CITY))),
np.where(df5['Wind_Risk']==1,( ' Heavy Wind forecasted at ' +df5.L
我想使用Conv1D使扩展卷积网络成为序列数据集。
所以我尝试了波士顿数据集的Conv1D。
from tensorflow.python.keras.layers import Conv1D, MaxPooling2D
from tensorflow.python.keras.layers import Activation, Dropout, Flatten, Input, Dense
from tensorflow.python.keras.models import Model
from sklearn.datasets import load_boston
from sklearn.
我不明白。这些文档解释了广播的规则,但似乎没有用英语来定义它。我的猜测是,广播是当NumPy用虚拟数据填充一个较小的维度数组以执行操作时。但这不管用:
>>> x = np.array([1,3,5])
>>> y = np.array([2,4])
>>> x+y
*** ValueError: operands could not be broadcast together with shapes (3,) (2,)
但是,错误信息暗示我走在正确的轨道上。有人可以定义广播,然后提供一些简单的例子来说明什么时候起作用,什么时候不起作用?
假设我有10枚硬币来自同一张薄荷糖,我把它们翻50次,现在我想估计造币机的偏差以及所有硬币的个人偏见。
我想这样做是这样的:
# Generate a list of 10 arrays with 50 flips in each
test = [bernoulli.rvs(0.5, size=50) for x in range(10)]
with pm.Model() as test_model:
k = pm.Gamma('k', 0.01, 0.01) + 2
w = pm.Beta('w', 1, 1)
thetas = pm.Be
我正在尝试用于文本分类的基本Tensorflow JS模型,但是我得到了这个形状错误
(node:11400) UnhandledPromiseRejectionWarning: Error: Length of values '33693' does not match the size inferred by the shape '10000'.
这是我的密码
var X_Train = // tokenize sentences
var Y_Train = // encoded label
const xs = tf.tensor2d(X_Train);
我尝试使用Google运行我的keras UNet模型,而我在UpSampling2D中遇到了这个问题。有什么解决办法或解决办法吗?
要运行的代码:
import os
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import UpSampling2D
model = Sequential()
model.add(UpSampling2D((2, 2), input_shape=(16, 16, 1)
环境是Mac M1和miniforge Conda with python3.8。我已经完成了以下命令来安装tensorflow和tensorflow_hub: conda install -c apple tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal
# tried all the conda commands here (https://anaconda.org/conda-forge/tensorflow-hub) and the following
pip install tens