- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在tensorflow 1.14.0中实现滑动DFT算法并使用tf.function,这样我就不必太担心控制流,但是我遇到了问题。当我尝试将变量的一个元素分配给该变量中的另一个元素时,我收到有关跨步切片分配中的不兼容类型的错误。
我尝试过使用 tf.scatter update、tf allocate 以及仅使用典型的切片分配,但是这些都不起作用。
@tf.function
def sdft_func(self,input_tensor):
for i in range(self.N_t):
#retrieving variables so that I have direct access to it
#instead of getting access to the read tensor
_, _, self.in_s = self.get_variables()
last = self.in_s[self.N_t-1]
for j in range(self.N_t,0,-1):
_, _, self.in_s = self.get_variables()
val = self.in_s[j-1]
#The line below gives the error
self.in_s = self.in_s[j].assign(val)
print(self.in_s)
我收到的错误如下:
TypeError: In op 'strided_slice_1/_assign', input types ([tf.complex64, tf.int32, tf.int32, tf.int32, tf.complex64]) are not compatible with expected types ([tf.complex64_ref, tf.int32, tf.int32, tf.int32, tf.complex64])
提前谢谢您!
最佳答案
看来我缩小了问题范围,因为它与尝试在 tf.function 函数内部设置 tf.complex64 变量有关。因此,为了克服这个问题,我简单地抽象了该操作,以便在 tf.function 函数之外完成变量设置。解决方法见下文:
def sdft_func(self,input_tensor):
@tf.function
def func(input_tensor,N_t,in_s,coeffs,freqs):
in_s = tf.identity(in_s)
coeffs = tf.identity(coeffs)
freqs = tf.identity(freqs)
for i in range(N_t):
last = in_s[self.N_t-1]
in_s = in_s[:-1]
new_val = tf.expand_dims(tf.complex(input_tensor[i],
tf.cast(0.0,dtype=tf.float32)),0)
in_s = tf.concat([new_val,in_s],axis=0)
delta = in_s[0] - last
freqs_2 = tf.TensorArray(tf.complex64,size=self.N)
for j in range(self.N_t):
freqs_2 = freqs_2.write(j,(freqs[j]+delta)*coeffs[j])
freqs = freqs_2.stack()
freqs.set_shape([self.N])
return freqs,in_s
new_freqs, new_in_s = func(input_tensor,self.N_t,
self.in_s,self.coeffs,self.freqs)
self.in_s = self.in_s.assign(new_in_s)
self.freqs = self.freqs.assign(new_freqs)
关于python - 如何修复签名中 Tensorflow 1.14.0rc 中的 'strided slice assignment are not compatible with expected types'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57547036/
在嵌入式系统的背景下,给出以下函数结构: 返回变量的条件赋值: int foo(int x) { int status; if (is_valid(x)) {
#input |--IDs-|--Value-| |--da1-|--100---| |--da2-|---80---| |--da3-|--200---| |--da4-|--300---| |--
您可以declare a list of variables and assign them some value在 Perl 6 my ($a, $b) = 33,44 # $a will be 3
在下面的代码中实现对象的浅拷贝,但是不同的输出让我很困惑: 对象.分配: var obj = { name: 'wsscat', age: 0, add: { a: 'beijin
我正在查看一位已不复存在的开发人员的一些旧代码,并注意到有时他使用 Object.assign({}, xyz) 还有他用过的其他东西 Object.assign([], abc); 两者有区别吗?
这个问题在这里已经有了答案: Why were ES5 Object methods not added to Object.prototype? (2 个答案) 关闭 4 个月前。 我正在做一个
我想知道这之间的区别: Object.assign(otherObject, { someNewProperty: '' }); 和 otherObject.someNewProperty = '
考虑以下代码: const defaultState = () => { return { profile: { id: '', displayName: '',
我刚刚偶然发现this line of TS code : const { title = item.text } = item; 这似乎是一个destructuring assigment但是大括号
我是一个没有经验的 JavaScript 用户,正在阅读这本书 CoffeeScript: Accelerated JavaScript Development ,其中作者制作了一种 Scrabble
当我查看日志文件时 D:\SAS\XXX\Lev1\SASMain\BatchServer\Logs 我看到了这两行 NOTE: Libref TESTLIB successfully assigne
我似乎不明白为什么要使用移动赋值运算符: CLASSA & operator=(CLASSA && other); //move assignment operator 结束了,复制赋值运算符: CL
在Eiffel Studio中,我一直试图访问从另一个类定义的一个类的对象的字段。但是,它不断给出我无法理解和解决的错误。以下是示例代码片段: 创建对象的类: class TEST1 feat
为什么这个片段在 Node (10.5) .then(function() { this = {...this, ...payload}; this.update();
我在我的 React 应用程序中使用以下包来生成 Recaptcha 组件:https://github.com/appleboy/react-recaptcha 组件如下所示,带有 eslint 警
我有以下代码: #include #include using std::cout; struct SomeType { SomeType() {} SomeType(const Some
我有这个代码示例: var a = 10; ({a}) = 0; 在 Google Chrome 中,它显示错误:SyntaxError:无效的解构赋值目标 在 Firefox 中,它显示错误:Ref
我有一个函数,用于对两个输入字段的输入求和并将其分配给一个。我的函数如下所示: function sum(id) { nextId = id+2 console.log
我收到这个警告 "Automatic Reference Counting Issue: Assigning retained object to unsafe_unretained variable
在使用 Shopify 的 Liquid 语言编码时,我注意到使用以下语法分配了一些变量: {%- assign variable = value -%} 和使用以下语法分配的其他变量: {% ass
我是一名优秀的程序员,十分优秀!