我有一个新的数据集微调初始模型,并在Keras中将其保存为".h5"模型.现在我的目标是在android Tensorflow上运行我的模型,它只接受".pb"扩展名.问题是Keras或tensorflow中是否有任何库进行此转换?到目前为止我看过这篇文章:https: //blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html但还不清楚.
在这个问题的评论中讨论的上下文中提到,虽然连接一串字符串只是简单地''.join([str1, str2, ...])
连接,但连接一系列列表就像是list(itertools.chain(lst1, lst2, ...))
,尽管你也可以使用列表理解[x for y in [lst1, lst2, ...] for x in y]
.让我感到惊讶的是,第一种方法始终比第二种方法更快:
import random
import itertools
random.seed(100)
lsts = [[1] * random.randint(100, 1000) for i in range(1000)]
%timeit [x for y in lsts for x in y]
# 39.3 ms ± 436 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
%timeit list(itertools.chain.from_iterable(lsts))
# 30.6 ms ± 866 µs per loop (mean ± std. dev. …
Run Code Online (Sandbox Code Playgroud) 早在TensorFlow <2.0中,我们通过将图层分组为或来定义图层,尤其是更复杂的设置,例如初始模块。tf.name_scope
tf.variable_scope
利用这些运算符,我们可以方便地构建计算图,从而使TensorBoard的图视图更容易解释。
这对于调试复杂的体系结构非常方便。
不幸的是,tf.keras
似乎没有理会,tf.name_scope
并且tf.variable_scope
在TensorFlow> = 2.0中消失了。因此,这样的解决方案...
with tf.variable_scope("foo"):
with tf.variable_scope("bar"):
v = tf.get_variable("v", [1])
assert v.name == "foo/bar/v:0"
Run Code Online (Sandbox Code Playgroud)
...不再可用。有替代品吗?
我们如何在TensorFlow> = 2.0中对图层和整个模型进行分组?如果我们不对图层进行分组,那么tf.keras
只需将所有内容依次放置在图形视图中,就会给复杂的模型造成很大的混乱。
有替代品tf.variable_scope
吗?到目前为止我找不到任何东西,但是在TensorFlow <2.0中大量使用了该方法。
编辑:我现在已经为TensorFlow 2.0实现了一个示例。这是使用tf.keras
以下命令实现的简单GAN :
# Generator
G_inputs = tk.Input(shape=(100,), name=f"G_inputs")
x = tk.layers.Dense(7 * 7 * 16)(G_inputs)
x = tf.nn.leaky_relu(x)
x = tk.layers.Flatten()(x)
x = tk.layers.Reshape((7, 7, 16))(x)
x = tk.layers.Conv2DTranspose(32, (3, 3), padding="same")(x)
x = …
Run Code Online (Sandbox Code Playgroud) 我有一个复制/移动探测课:
#include <iostream>
struct A
{
A()
{
std::cout << "Creating A" << std::endl;
}
~A() noexcept
{
std::cout << "Deleting A" << std::endl;
}
A(const A &)
{
std::cout << "Copying A" << std::endl;
}
A(A &&) noexcept
{
std::cout << "Moving A" << std::endl;
}
A &operator=(const A &)
{
std::cout << "Copy-assigning A" << std::endl;
return *this;
}
A &operator=(A &&) noexcept
{
std::cout << "Move-assigning A" << std::endl;
return *this;
}
};
Run Code Online (Sandbox Code Playgroud)
我发现跑步:
#include <vector>
int …
Run Code Online (Sandbox Code Playgroud) 对于模糊的问题名称,我们深表歉意,但我不确定如何调用此操作。
我有以下数据框:
import pandas as pd
df = pd.DataFrame({
'A': [1, 3, 2, 1, 2],
'B': [2, 1, 3, 2, 3],
'C': [3, 2, 1, 3, 1],
})
print(df)
# A B C
# 0 1 2 3
# 1 3 1 2
# 2 2 3 1
# 3 1 2 3
# 4 2 3 1
Run Code Online (Sandbox Code Playgroud)
这个数据代表一个“排行榜”的每个选项的,A
,B
并C
为每一行。因此,举例来说,在排2
,C
是最好的,然后A
,然后B
。我想构建“反向”的数据帧,其中,对于每一行,我有三列的1
,2
和3
排名,具有的位置A …
我知道,在C++中,当你写作时
int i;
Run Code Online (Sandbox Code Playgroud)
在有效地为其赋值之前,您不能对变量将保持的值做任何假设.但是,如果你写
int i = int();
Run Code Online (Sandbox Code Playgroud)
那么你有保证i
会0
.所以我的问题是,它实际上并不是语言行为的一种不完整性吗?我的意思是,如果我已经定义了一个类MyClass
并且写了
MyClass myInstance;
Run Code Online (Sandbox Code Playgroud)
我可以放心,没有类参数的默认构造函数将被调用以初始化myInstance
(如果没有,编译器将失败),因为这就是RAII原理的方式.但是,当涉及到原始类型时,资源获取似乎不再是初始化.这是为什么?
我不认为改变从C继承的这种行为会破坏任何现有的代码(世界上是否有任何代码假设不能对变量的值做出假设?),所以主要可能的原因我想到的就是性能,例如在创建基本类型的大数组时; 但是,我还想知道是否有一些官方解释.
谢谢.
我正在使用Keras TensorBoard回调.我想运行网格搜索并可视化张量板中每个模型的结果.问题是不同运行的所有结果合并在一起,损失情节是这样的混乱:
这里是网格搜索的代码:
df = pd.read_csv('data/prepared_example.csv')
df = time_series.create_index(df, datetime_index='DATE', other_index_list=['ITEM', 'AREA'])
target = ['D']
attributes = ['S', 'C', 'D-10','D-9', 'D-8', 'D-7', 'D-6', 'D-5', 'D-4',
'D-3', 'D-2', 'D-1']
input_dim = len(attributes)
output_dim = len(target)
x = df[attributes]
y = df[target]
param_grid = {'epochs': [10, 20, 50],
'batch_size': [10],
'neurons': [[10, 10, 10]],
'dropout': [[0.0, 0.0], [0.2, 0.2]],
'lr': [0.1]}
estimator = KerasRegressor(build_fn=create_3_layers_model,
input_dim=input_dim, output_dim=output_dim)
tbCallBack = TensorBoard(log_dir='./Graph', histogram_freq=0, write_graph=True, write_images=False)
grid = GridSearchCV(estimator=estimator, param_grid=param_grid, n_jobs=-1, scoring=bug_fix_score,
cv=3, verbose=0, fit_params={'callbacks': …
Run Code Online (Sandbox Code Playgroud) 我目前正在一个稍大的 TensorFlow 项目中工作,并尝试像往常一样可视化网络的某些变量,即执行此工作流程
tf.summary.scalar('loss', loss)
summary_op = tf.summary.merge_all()
writer = tf.summary.FileWriter('PATH')
并添加图表s = sess.run(summary_op)
writer.add_summary(s, epoch)
通常这对我有用。但这一次,我只显示了图表,当我检查事件文件时,我发现它是空的。巧合的是,我发现有人建议writer.flush()
在添加我的摘要作为第 6 步后使用。这解决了我的问题。
因此,合乎逻辑的后续问题是:我必须何时以及如何使用FileWriter.flush()
才能使 tensorflow 正常工作?
我是 tensorflow keras 和数据集的新手。谁能帮我理解为什么下面的代码不起作用?
import tensorflow as tf
import tensorflow.keras as keras
import numpy as np
from tensorflow.python.data.ops import dataset_ops
from tensorflow.python.data.ops import iterator_ops
from tensorflow.python.keras.utils import multi_gpu_model
from tensorflow.python.keras import backend as K
data = np.random.random((1000,32))
labels = np.random.random((1000,10))
dataset = tf.data.Dataset.from_tensor_slices((data,labels))
print( dataset)
print( dataset.output_types)
print( dataset.output_shapes)
dataset.batch(10)
dataset.repeat(100)
inputs = keras.Input(shape=(32,)) # Returns a placeholder tensor
# A layer instance is callable on a tensor, and returns a tensor.
x = keras.layers.Dense(64, activation='relu')(inputs)
x = keras.layers.Dense(64, activation='relu')(x) …
Run Code Online (Sandbox Code Playgroud) 我读了张量流的 tf.nn.max_pool 中的“SAME”和“VALID”填充有什么区别?但这对我的实验来说不是真的。
import tensorflow as tf
inputs = tf.random_normal([1, 64, 64, 3])
print(inputs.shape)
conv = tf.keras.layers.Conv2D(6, 4, strides=2, padding='same')
outputs = conv(inputs)
print(outputs.shape)
Run Code Online (Sandbox Code Playgroud)
产生
(1, 64, 64, 3)
(1, 32, 32, 6)
Run Code Online (Sandbox Code Playgroud)
. 但是,按照上面的链接会产生,(1, 31, 31, 6)
因为没有任何填充的过滤器范围之外没有额外的值。
带有 padding='same' 和 strides > 1 的 tf.keras.layers.Conv2D 表现如何?
我想知道确切的答案及其证据。
python ×8
tensorflow ×6
keras ×4
tensorboard ×3
c++ ×2
c++11 ×1
constructor ×1
flatten ×1
pandas ×1
primitive ×1
raii ×1
scikit-learn ×1
vector ×1