小编mic*_*rer的帖子

Python 2:SMTPServerDisconnected:连接意外关闭

使用Python发送电子邮件时遇到一个小问题:

#me == my email address
#you == recipient's email address
me = "some.email@gmail.com"
you = "some_email2@gmail.com"

# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Alert"
msg['From'] = me
msg['To'] = you

# Create the body of the message (a plain-text and an HTML version).
html = '<html><body><p>Hi, I have the following alerts for you!</p></body></html>'

# Record the MIME types of both parts - text/plain and text/html.
part2 = MIMEText(html, 'html')

# …
Run Code Online (Sandbox Code Playgroud)

python email smtp python-2.7

17
推荐指数
3
解决办法
5万
查看次数

无法获得tensorflow DNNClassifier的预测

我正在使用MNIST教程中的代码:

feature_columns = [tf.contrib.layers.real_valued_column("", dimension=4)]
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
                                            hidden_units=[10, 20, 10],
                                            n_classes=2,
                                            model_dir="/tmp/iris_model")

classifier.fit(x=np.array(train, dtype = 'float32'),
               y=np.array(y_tr, dtype = 'int64'),
               steps=2000)

accuracy_score = classifier.evaluate(x=np.array(test, dtype = 'float32'),
                                     y=y_test)["auc"]
print('AUC: {0:f}'.format(accuracy_score))

from tensorflow.contrib.learn import SKCompat
ds_test_ar = np.array(ds_test, dtype = 'float32')

ds_predict_tf = classifier.predict(input_fn = _my_predict_data)
print('Predictions: {}'.format(str(ds_predict_tf)))
Run Code Online (Sandbox Code Playgroud)

但最后我得到了以下结果而不是预测:

Predictions: <generator object DNNClassifier.predict.<locals>.<genexpr> at 0x000002CE41101CA8>
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

python tensorflow

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

如何使用tf.data.Dataset.from_generator()将参数发送到生成器函数?

我想创建一些tf.data.Dataset使用该from_generator()功能.我想向生成器函数(raw_data_gen)发送一个参数.这个想法是生成器函数将根据发送的参数产生不同的数据.通过这种方式,我希望raw_data_gen能够提供培训,验证或测试数据.

training_dataset = tf.data.Dataset.from_generator(raw_data_gen, (tf.float32, tf.uint8), ([None, 1], [None]), args=([1]))

validation_dataset = tf.data.Dataset.from_generator(raw_data_gen, (tf.float32, tf.uint8), ([None, 1], [None]), args=([2]))

test_dataset = tf.data.Dataset.from_generator(raw_data_gen, (tf.float32, tf.uint8), ([None, 1], [None]), args=([3]))
Run Code Online (Sandbox Code Playgroud)

我尝试以from_generator()这种方式调用时收到的错误消息是:

TypeError: from_generator() got an unexpected keyword argument 'args'
Run Code Online (Sandbox Code Playgroud)

这是raw_data_gen函数,虽然我不确定你是否需要这个,因为我的预感是问题是调用from_generator():

def raw_data_gen(train_val_or_test):

    if train_val_or_test == 1:        
        #For every filename collected in the list
        for filename, lab in training_filepath_label_dict.items():
            raw_data, samplerate = soundfile.read(filename)
            try: #assume the audio is stereo, …
Run Code Online (Sandbox Code Playgroud)

python python-3.x tensorflow tensorflow-datasets

6
推荐指数
1
解决办法
888
查看次数

什么时候应该使用 tf.train.BytesList、tf.train.FloatList 和 tf.train.Int64List 来存储要存储在 tf.train.Feature 中的数据?

TensorFlow 提供 3 种不同格式的数据存储在tf.train.Feature. 这些是:

tf.train.BytesList
tf.train.FloatList
tf.train.Int64List
Run Code Online (Sandbox Code Playgroud)

我经常在tf.train.Int64List/tf.train.FloatListtf.train.BytesList.

我在网上看到一些例子,它们将整数/浮点数转换为字节,然后将它们存储在tf.train.BytesList. 这比使用其他格式之一更可取吗?如果是这样,当您可以将它们转换为字节并使用时,为什么 TensorFlow 甚至提供tf.train.Int64Listtf.train.FloatList作为可选格式tf.train.BytesList

谢谢你。

python dataformat tensorflow

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

为什么在设置pos = [50,0]时,psychopy.visual.TextStim不会呈现文本?

我想使用visual.TextStim将文本渲染到visual.Window的右侧.当我将TextStim的位置设置为0时:

my_text = visual.TextStim(win, pos=[0,0])
Run Code Online (Sandbox Code Playgroud)

文本显示在屏幕上.但当我改为:

my_text = visual.TextStim(win, pos=[50,0])
Run Code Online (Sandbox Code Playgroud)

例如.文本没有出现.我用python 3.6,psychopy 1.90.2试过这个.如何使用TextStim在visual.Window右侧显示文本刺激?

python python-2.7 python-3.x psychopy

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