标签: tflearn

将Tensorboard嵌入元数据链接到检查点

我在tensorflow上使用tflearn包装器来构建模型,并想将元数据(标签)添加到结果嵌入可视化中。运行后,有没有办法将metadata.tsv文件链接到保存的检查点?

我已经在检查点摘要的日志目录中创建了projection_config.pbtxt文件,并且metas.tsv位于同一文件夹中。配置看起来像这样:

embeddings {
  tensor_name: "Embedding/W"
  metadata_path: "C:/tmp/tflearn_logs/shallow_lstm/"
}
Run Code Online (Sandbox Code Playgroud)

并使用文档中的代码创建-https: //www.tensorflow.org/how_tos/embedding_viz/

我已经注释掉了tf.Session部分,希望创建元数据链接而无需直接在Session对象中这样做,但是我不确定是否可行。

from tensorflow.contrib.tensorboard.plugins import projector
#with tf.Session() as sess:
config = projector.ProjectorConfig()
# One can add multiple embeddings.
embedding = config.embeddings.add()
embedding.tensor_name = 'Embedding/W'
# Link this tensor to its metadata file (e.g. labels).
embedding.metadata_path = 'C:/tmp/tflearn_logs/shallow_lstm/'
# Saves a config file that TensorBoard will read during startup.
projector.visualize_embeddings(tf.summary.FileWriter('/tmp/tflearn_logs/shallow_lstm/'), config)
Run Code Online (Sandbox Code Playgroud)

以下是当前嵌入可视化的快照。注意空的元数据。有没有一种方法可以将所需的图元文件直接附加到此嵌入?

嵌入可视化

metadata embedding tensorflow tensorboard tflearn

5
推荐指数
1
解决办法
5500
查看次数

tf.contrib.learn.LinearRegressor为具有一个功能的数据构建意外的坏模型

我正在为来自csv的数据构建一个简单的线性回归量.数据包括一些人的体重和身高.整体学习过程非常简单:

MAX_STEPS = 2000
# ...
features = [tf.contrib.layers.real_valued_column(feature_name) for feature_name in FEATURES_COL]
# ...
linear_regressor = tf.contrib.learn.LinearRegressor(feature_columns=features)
linear_regressor.fit(input_fn=prepare_input, max_steps=MAX_STEPS)
Run Code Online (Sandbox Code Playgroud)

然而,由回归量构建的模型出乎意料地是坏的.结果可以用下一张图片说明: 在此输入图像描述

可视化代码(以防万一):

plt.plot(height_and_weight_df_filtered[WEIGHT_COL], 
         linear_regressor.predict(input_fn=prepare_full_input), 
         color='blue',
         linewidth=3)
Run Code Online (Sandbox Code Playgroud)

以下是scikit-learn为LinearRegression类提供的相同数据:

lr_updated = linear_model.LinearRegression()
lr_updated.fit(weight_filtered_reshaped, height_filtered)
Run Code Online (Sandbox Code Playgroud)

和可视化: 在此输入图像描述

增加步骤量无效.我会假设我以错误的方式使用TensorFlow中的回归量.

带代码的iPython笔记本.

linear-regression tensorflow tflearn

4
推荐指数
1
解决办法
413
查看次数

TFLearn - 什么是 input_data

我遇到了以下声明:

convnet = input_data(shape=[None,img_size,img_size,1], name='input')
Run Code Online (Sandbox Code Playgroud)

我试图寻找描述,但找不到明确的解释。

我的主要问题是该功能input_data主要做什么?它就像我们输入数据的占位符吗?

关于形状,什么是None开头,什么是1结尾?

谢谢。

python machine-learning deep-learning tensorflow tflearn

4
推荐指数
1
解决办法
2264
查看次数

Tflearn 训练批次错误表示“'Tensor' 类型的对象没有 len()”

我是张量流的新手。我正在使用 Tflearn 来训练我的图像以对眼睛状态进行分类。对于初始阶段,现在,我有 400 张训练图像和 200 张验证图像。我正在使用 image_preloader 在我的脚本中输入自定义图像。我认为它成功加载图像显示:

tflearn.data_utils.ImagePreloader 对象在 0x7fa28f3a5310

但是在训练时划分和获取批次时会导致问题,

给出一个回溯错误作为

Traceback (most recent call last):
  File "tflearn_custom.py", line 181, in <module>
    model.fit(x,y,validation_set=({'input':test_x},{'targets':test_y}),n_epoch=10,batch_size=10)
  File "/usr/local/lib/python2.7/dist-packages/tflearn/models/dnn.py", line 215, in fit
    callbacks=callbacks)
  File "/usr/local/lib/python2.7/dist-packages/tflearn/helpers/trainer.py", line 285, in fit
    self.summ_writer, self.coord)
  File "/usr/local/lib/python2.7/dist-packages/tflearn/helpers/trainer.py", line 709, in initialize_fit
    self.n_train_samples = len(get_dict_first_element(feed_dict))
TypeError: object of type 'Tensor' has no len()
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import tflearn 
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout,fully_connected
from tflearn.layers.estimator import regression 
import tensorflow as tf
from …
Run Code Online (Sandbox Code Playgroud)

python tensorflow tflearn

3
推荐指数
1
解决办法
6438
查看次数

如何为TensorFlow分类器创建要素列

我在csv文件中有一个非常简单的二进制分类数据集,如下所示:

"feature1","feature2","label"
1,0,1
0,1,0
...
Run Code Online (Sandbox Code Playgroud)

其中"label"列表示类(1为正,0为负).功能的数量实际上相当大,但对于那个问题并不重要.

以下是我阅读数据的方法:

train = pandas.read_csv(TRAINING_FILE)
y_train, X_train = train['label'], train[['feature1', 'feature2']].fillna(0)

test = pandas.read_csv(TEST_FILE)
y_test, X_test = test['label'], test[['feature1', 'feature2']].fillna(0)
Run Code Online (Sandbox Code Playgroud)

我想运行tensorflow.contrib.learn.LinearClassifiertensorflow.contrib.learn.DNNClassifier对这些数据.例如,我像这样初始化DNN:

classifier = DNNClassifier(hidden_units=[3, 5, 3],
                               n_classes=2,
                               feature_columns=feature_columns, # ???
                               activation_fn=nn.relu,
                               enable_centered_bias=False,
                               model_dir=MODEL_DIR_DNN)
Run Code Online (Sandbox Code Playgroud)

那么,feature_columns当所有特征都是二进制(0或1是唯一可能的值)时,我应该如何创建?

这是模型培训:

classifier.fit(X_train.values,
                   y_train.values,
                   batch_size=dnn_batch_size,
                   steps=dnn_steps)
Run Code Online (Sandbox Code Playgroud)

fit()用输入函数替换参数的解决方案也很棒.

谢谢!

PS我正在使用TensorFlow版本1.0.1

machine-learning neural-network deep-learning tensorflow tflearn

3
推荐指数
1
解决办法
4806
查看次数

tf.contrib.learn load_csv_with_header在TensorFlow 1.1中不起作用

我安装了最新的TensorFlow(v1.1.0),并尝试运行tf.contrib.learn快速入门教程,您可以在其中为IRIS数据集构建分类器.但是,当我尝试时:

training_set = tf.contrib.learn.datasets.base.load_csv_with_header(
    filename=IRIS_TRAINING,
    target_dtype=np.int,
    features_dtype=np.float32)
Run Code Online (Sandbox Code Playgroud)

我收到了一个StopIteration错误.

当我检查API时,我没有找到任何关于load_csv_with_header().他们是否在最新版本中更改了它而没有更新教程?我怎样才能解决这个问题?

编辑:如果这有任何区别,我使用Python3.6.

python tensorflow tflearn

3
推荐指数
1
解决办法
2625
查看次数

如何在 Windows 10 的 anaconda 发行版上安装 tflearn 模块

我已经在 anaconda 上安装了大部分库。在我的一个代码中显示没有名为“tflearn”的模块。

我还使用了命令 conda install tflearn。它显示失败的消息。

   PackagesNotFoundError: The following packages are not available from 
   current channels:
Run Code Online (Sandbox Code Playgroud)
  • 学习

当前频道:

python-3.x anaconda tensorflow tflearn

3
推荐指数
1
解决办法
2万
查看次数

Tensorflow:尽管数据中没有字符串,但使用 tflearn 时不支持将字符串转换为浮点数错误

我似乎无法在我的代码中找到错误,其中有任何字符串被错误地转换为浮点数。但它却给了我这个错误:

W tensorflow/core/framework/op_kernel.cc:958] Unimplemented: Cast string to float is not supported
E tensorflow/core/common_runtime/executor.cc:334] Executor failed to create kernel. Unimplemented: Cast string to float is not supported
     [[Node: Adam/apply_grad_op_0/update_FullyConnected_1/b/Cast_2 = Cast[DstT=DT_FLOAT, SrcT=DT_STRING, _class=["loc:@FullyConnected_1/b"], _device="/job:localhost/replica:0/task:0/cpu:0"](Adam/apply_grad_op_0/learning_rate)]]
W tensorflow/core/framework/op_kernel.cc:958] Unimplemented: Cast string to float is not supported
E tensorflow/core/common_runtime/executor.cc:334] Executor failed to create kernel. Unimplemented: Cast string to float is not supported
     [[Node: Adam/apply_grad_op_0/update_Conv2D/W/Cast_2 = Cast[DstT=DT_FLOAT, SrcT=DT_STRING, _class=["loc:@Conv2D/W"], _device="/job:localhost/replica:0/task:0/cpu:0"](Adam/apply_grad_op_0/learning_rate)]]
--
Traceback (most recent call last):
  File "code.py", line 63, in <module>
    snapshot_step = 100, …
Run Code Online (Sandbox Code Playgroud)

python tensorflow tflearn

2
推荐指数
1
解决办法
8925
查看次数

AttributeError:模块'tensorflow'没有属性'unpack'

我试图lstm使用tfLearn 运行模型,我收到此错误:

File "...city_names.py", line 16, in <module>
g = tflearn.lstm(g, 256, activation='relu', return_seq=True)
File "...\tflearn\layers\recurrent.py", line 197, in lstm
inference = tf.unpack(inference)
AttributeError: module 'tensorflow' has no attribute 'unpack'
Run Code Online (Sandbox Code Playgroud)

使用以下行:

g = tflearn.input_data(shape=[None, maxlen, len(char_idx)])
Run Code Online (Sandbox Code Playgroud)

这些是代码行:

path = "US_cities.txt"
maxlen = 20
X, Y, char_idx = textfile_to_semi_redundant_sequences(path, seq_maxlen=maxlen, redun_step=3)
g = tflearn.input_data(shape=[None, maxlen, len(char_idx)])
g = tflearn.input_data(shape=[None, maxlen, len(char_idx)])
Run Code Online (Sandbox Code Playgroud)

tensorflow tflearn

2
推荐指数
1
解决办法
4287
查看次数

如何在python中以随机角度旋转3D图像

我正在使用一组32x32x32灰度图像,我想在图像上应用随机旋转作为数据增强的一部分,同时通过tflearn + tensorflow训练CNN.我使用以下代码来执行此操作:

    # Real-time data preprocessing
    img_prep = ImagePreprocessing()
    img_prep.add_featurewise_zero_center()
    img_prep.add_featurewise_stdnorm()


    # Real-time data augmentation
    img_aug = ImageAugmentation()
    img_aug.add_random_rotation(max_angle=360.)

    # Input data
    with tf.name_scope('Input'):
        X = tf.placeholder(tf.float32, shape=(None, image_size, 
    image_size, image_size, num_channels), name='x-input')
        Y = tf.placeholder(tf.float32, shape=(None, label_cnt), name='y-input')


    # Convolutional network building
    network = input_data(shape=[None, 32, 32, 32, 1],
                 placeholder = X,
                 data_preprocessing=img_prep,
                 data_augmentation=img_aug)
Run Code Online (Sandbox Code Playgroud)

(我正在使用tensorflow和tflearn的组合来使用两者的功能,所以请耐心等待.如果我使用占位符等方式出现问题,请告诉我.)

我发现使用add_random_rotation(它本身使用scipy.ndimage.interpolation.rotate)将我的灰度图像的第三维视为通道(如RGB通道),并通过围绕z轴的随机角度旋转第三维的所有32个图像(将我的3D图像视为具有32个通道的2D图像).但我希望图像在空间中旋转(围绕所有三个轴).你知道我怎么能这样做吗?是否有用于在空间中轻松旋转3D图像的功能或包装?!

python image deep-learning tensorflow tflearn

2
推荐指数
1
解决办法
3214
查看次数

形状必须为 1 级,但为 2 级 tflearn 错误

我正在使用 提供的 DNNtflearn从一些数据中学习。我的data变量的形状为(6605, 32),我的labels数据的形状为(6605,),我在下面的代码中将其重塑为(6605, 1)......

# Target label used for training
labels = np.array(data[label], dtype=np.float32)

# Reshape target label from (6605,) to (6605, 1)
labels = tf.reshape(labels, shape=[-1, 1])

# Data for training minus the target label.
data = np.array(data.drop(label, axis=1), dtype=np.float32)

# DNN
net = tflearn.input_data(shape=[None, 32])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 1, activation='softmax')
net = tflearn.regression(net)

# Define model.
model …
Run Code Online (Sandbox Code Playgroud)

machine-learning neural-network python-3.x tensorflow tflearn

2
推荐指数
1
解决办法
2万
查看次数