我正在使用 Google 的 TensorFlow DeepDream 实现(https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/deepdream/deepdream.ipynb)在目录中迭代做深度梦境图像。
我的代码如下:
model_fn = tensorflow_inception_graph.pb
# creating TensorFlow session and loading the model
graph = tf.Graph()
sess = tf.InteractiveSession(graph=graph)
with tf.gfile.FastGFile(model_fn, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
t_input = tf.placeholder(np.float32, name='input') # define the input tensor
imagenet_mean = 117.0
t_preprocessed = tf.expand_dims(t_input-imagenet_mean, 0)
tf.import_graph_def(graph_def, {'input':t_preprocessed})
def render_deepdream(t_obj, img0=img_noise,
iter_n=10, step=1.5, octave_n=4, octave_scale=1.4):
t_score = tf.reduce_mean(t_obj) # defining the optimization objective
t_grad = tf.gradients(t_score, t_input)[0] # behold the power of automatic differentiation!
# …Run Code Online (Sandbox Code Playgroud) 我正在使用序列到序列语言模型,在更改代码以将自定义词嵌入权重传递到 Embeddings 层后,当我尝试在 gpu 上训练时收到 OOM 错误。
这是相关的代码:
def create_model(word_map, X_train, Y_train, vocab_size, max_length):
# define model
model = Sequential()
# get custom embedding weights as matrix
embedding_matrix = get_weights_matrix_from_word_map(word_map)
model.add(Embedding(len(word_map)+1, 300, weights=[embedding_matrix], input_length=max_length-1))
model.add(LSTM(50))
model.add(Dense(vocab_size, activation='softmax'))
print(model.summary())
# compile network
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X_train, Y_train, epochs=100, verbose=2)
return model
Run Code Online (Sandbox Code Playgroud)
这是来自服务器的完整错误日志:
File "/home2/slp24/thesis/UpdatedLanguageModel_7_31.py", line 335, in create_model_2
model.fit(X_train, Y_train, batch_size=32, epochs=1, verbose=2) ## prev X, y
File "/opt/python-3.4.1/lib/python3.4/site-packages/keras/models.py", line 963, in fit
validation_steps=validation_steps)
File "/opt/python-3.4.1/lib/python3.4/site-packages/keras/engine/training.py", line 1682, in fit
self._make_train_function() …Run Code Online (Sandbox Code Playgroud) 我在 Jupyter Notebook 中编写了以下代码,它在 Tensorflow 中执行线性回归:
import tensorflow as tf
import numpy as np
import pandas as pd
from sklearn.datasets import load_boston
import matplotlib.pyplot as plt
boston=load_boston()
type(boston)
boston.feature_names
bd=pd.DataFrame(data=boston.data,columns=boston.feature_names)
bd['Price']=pd.DataFrame(data=boston.target)
np.random.shuffle(bd.values)
W0=tf.Variable(0.0000000000003)
W1=tf.Variable(0.000000000002)
b=tf.Variable(0.0000000000001)
#print(bd.shape[1])
tf.summary.histogram('Weights', W0)
tf.summary.histogram('Weights', W1)
tf.summary.histogram('Biases', b)
dataset_input=bd.iloc[:, 0 : bd.shape[1]-1];
#dataset_input.head(2)
dataset_output=bd.iloc[:, bd.shape[1]-1]
dataset_output=dataset_output.values
dataset_output=dataset_output.reshape((bd.shape[0],1)) #converted (506,) to (506,1) because in pandas
#the shape was not changing and it was needed later in feed_dict
dataset_input=dataset_input.values #only dataset_input is in DataFrame form and converting it …Run Code Online (Sandbox Code Playgroud) 我使用Keras模拟神经网络,我试图用一个图来评估它acc和val_acc。我在以下代码行中有 3 个错误:
print(history.keys())错误是function' object has not attribute 'keys'y_pred = classifier.predict(X_test)错误是name 'classifier' is not definedplt.plot(history.history['acc'])错误是 'History' object is not subscriptable我也在尝试绘制 ROC 曲线,我该怎么做?
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import keras
from keras.models import Sequential
from keras.layers import Dense
from sklearn import cross_validation
from matplotlib import pyplot
from keras.utils import plot_model
dataset = pd.read_csv('Data_BP.csv')
X = dataset.iloc[:, 0:11].values
y = …Run Code Online (Sandbox Code Playgroud) 我正在学习 TensorFlow 和 LSTM,我想知道为什么当我训练它返回一个值时,我的预测输出有多个值。我的目标是在使用数组进行情感分析训练后获得 0 到 1 之间的单个值。
训练输入数据如下所示:
[[59, 21, ... 118, 194], ... [12, 110, ... 231, 127]]
Run Code Online (Sandbox Code Playgroud)
所有输入数组的长度相同,用 0 填充。训练目标数据如下所示:
[1.0, 0.5, 0.0, 1.0, 0.0 ...]
Run Code Online (Sandbox Code Playgroud)
模型:
model = Sequential()
model.add(Embedding(input_length, 64, mask_zero=True))
model.add(LSTM(100))
model.add(Dense(1, activation=tf.nn.sigmoid))
Run Code Online (Sandbox Code Playgroud)
为什么预测似乎一次评估每个单独的值而不是整个数组?
model.predict([192])
# Returns [[0.5491102]]
model.predict([192, 25])
# Returns [[0.5491102, 0.4923803]]
model.predict([192, 25, 651])
# Returns [[0.5491102, 0.4923803, 0.53853387]]
Run Code Online (Sandbox Code Playgroud)
我不想取输出的平均值,因为输入数组中的值之间的关系对于情感分析很重要。如果我正在训练预测单个值,我不明白为什么不输出单个值。我是 TensorFlow、Keras 和分层神经网络的新手,所以我确定我遗漏了一些明显的东西。
我正在尝试找到一种方法来使用 Tensorflow 服务并能够添加新模型和新版本的模型。我可以将 tensorflow 服务指向 S3 存储桶吗?
我还需要它作为容器运行吗?这是可能的还是我需要实现另一个程序来下拉模型并将其添加到共享卷并要求 tensorflow 更新文件系统中的模型?
或者我是否需要构建自己的 docker 镜像才能从 s3 中提取内容?
我正在使用自动编码器,如果重建图像是这样的,那没关系,因为输入图像丢失了很多高质量的 重建图像
我应该怎么做才能让图像看起来更像输入,因为我将使用输出图像进行人脸识别。
我应该编辑时代,批量大小..?。
基本上这个问题TensorFlow: Is there a way to convert a list with None type to a Tensor?
答案说明了为什么这是不可能的,但没有解决方法
我正在尝试制作一个自动编码器,它具有一些卷积层,这些层被展平为一些完全连接的层并重新扩展到原始维度。但是,当我尝试将展平层的输出扩展为张量时,我遇到了问题Tried to convert 'shape' to a tensor and failed. Error: Cannot convert a partially known TensorShape to a Tensor: (?, 14, 32, 128)
这基本上就是网络的样子
X=tf.placeholder(tf.float32,shape=[None, height, width, channel])
conv = Conv2D(32, (3, 3), activation='relu', padding='same')(X)
h1=actf(tf.matmul(conv,w)+b)
output = Conv2D(32, (3, 3), activation='relu', padding='same')(tf.reshape(h1, conv.shape))
Run Code Online (Sandbox Code Playgroud)
如何在不指定批量大小的情况下重塑中间层的输出?
我也试过
output = Conv2D(32, (3, 3), activation='relu', padding='same')(tf.reshape(h1, [None, 14, 32, 128]))
Run Code Online (Sandbox Code Playgroud)
这给出了以下错误 Failed to convert object …
尝试更改 tensorflow 对象检测模型中的标签,但无法打开 pbtxt 文件。可以告诉我是否有任何应用程序可以打开它吗?
Tensorflow 有几个基准测试工具:
我对 .pb 基准工具的参数有几个问题:
num_threads相关的单线程实验或通过使用tensorflow内螺纹平行运行次数?还有一些关于结果解释的问题:
count在结果输出?如何Timings (microseconds): count=相关--max_num_runs的参数?例子:
Run --num_threads=-1 --max_num_runs=1000:
2019-03-20 14:30:33.253584: I tensorflow/core/util/stat_summarizer.cc:85] Timings (microseconds): count=1000 first=3608 curr=3873 min=3566 max=8009 avg=3766.49 std=202
2019-03-20 14:30:33.253584: I tensorflow/core/util/stat_summarizer.cc:85] Memory (bytes): count=1000 curr=3301344(all same)
2019-03-20 14:30:33.253591: I tensorflow/core/util/stat_summarizer.cc:85] 207 nodes observed
2019-03-20 14:30:33.253597: I tensorflow/core/util/stat_summarizer.cc:85]
2019-03-20 14:30:33.378352: I tensorflow/tools/benchmark/benchmark_model.cc:636] FLOPs estimate: 116.65M
2019-03-20 14:30:33.378390: I tensorflow/tools/benchmark/benchmark_model.cc:638] FLOPs/second: 46.30B
Run --num_threads=1 --max_num_runs=1000:
2019-03-20 …Run Code Online (Sandbox Code Playgroud) tensorflow ×10
keras ×4
python ×4
autoencoder ×1
benchmarking ×1
lstm ×1
memory-leaks ×1
nlp ×1
python-3.x ×1
roc ×1
scikit-learn ×1
tensor ×1