小编Rub*_*res的帖子

Tensorflow==2.0.0a0 - AttributeError: module 'tensorflow' has no attribute 'global_variables_initializer'

I'm using Tensorflow==2.0.0a0 and want to run the following script:

import tensorflow as tf
import tensorboard
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import tensorflow_probability as tfp
from tensorflow_model_optimization.sparsity import keras as sparsity
from tensorflow import keras

tfd = tfp.distributions

init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)

    model = tf.keras.Sequential([
      tf.keras.layers.Dense(1,kernel_initializer='glorot_uniform'),
      tfp.layers.DistributionLambda(lambda t: tfd.Normal(loc=t, scale=1))
    ])
Run Code Online (Sandbox Code Playgroud)

All my older notebooks work with TF 1.13. However, I want to develop a notebook where I use …

python tensorflow tensorflow-estimator tf.keras

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

在Keras中设置LearningRateScheduler

我正在Keras中设置学习速率调度程序,使用历史记录丢失作为self.model.optimizer.lr的更新程序,但self.model.optimizer.lr上的值未插入SGD优化程序且优化程序是使用dafault学习率.代码是:

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.preprocessing import StandardScaler

class LossHistory(keras.callbacks.Callback):
    def on_train_begin(self, logs={}):
        self.losses = []
        self.model.optimizer.lr=3
    def on_batch_end(self, batch, logs={}):
        self.losses.append(logs.get('loss'))
        self.model.optimizer.lr=lr-10000*self.losses[-1]

def base_model():
    model=Sequential()
    model.add(Dense(4, input_dim=2, init='uniform'))
    model.add(Dense(1, init='uniform'))
    sgd = SGD(decay=2e-5, momentum=0.9, nesterov=True)


model.compile(loss='mean_squared_error',optimizer=sgd,metrics['mean_absolute_error'])
    return model

history=LossHistory()

estimator = KerasRegressor(build_fn=base_model,nb_epoch=10,batch_size=16,verbose=2,callbacks=[history])

estimator.fit(X_train,y_train,callbacks=[history])

res = estimator.predict(X_test)
Run Code Online (Sandbox Code Playgroud)

使用Keras作为连续变量的回归量,一切正常,但我想通过更新优化器学习率来达到更小的导数.

python optimization keras

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

如何使用 Gensim 生成葡萄牙语词嵌入?

我有以下问题:

在英语语言中,我的代码使用 Gensim 生成了成功的词嵌入,考虑到余弦距离,相似的短语彼此接近:

“响应时间和错误测量”和“用户感知响应时间与错误测量的关系”之间的夹角很小,因此它们是集合中最相似的短语。

在此处输入图片说明

但是,当我在葡萄牙语中使用相同的短语时,它不起作用:

在此处输入图片说明

我的代码如下:

import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
import matplotlib.pyplot as plt
from gensim import corpora
documents = ["Interface máquina humana para aplicações computacionais de laboratório abc",
          "Um levantamento da opinião do usuário sobre o tempo de resposta do sistema informático",
           "O sistema de gerenciamento de interface do usuário EPS",
           "Sistema e testes de engenharia de sistemas humanos de EPS",
           "Relação do tempo de resposta percebido pelo usuário para a medição de erro", …
Run Code Online (Sandbox Code Playgroud)

python nlp nltk gensim

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

AWS SageMaker 无权对资源执行:ecr:CreateRepository:*

我正在创建自己的 Docker 映像,以便可以在 AWS SageMaker 中使用自己的模型。我使用自定义 Dockerfile 在 SageMaker ml.t2.medium 实例中的 Jupyter Notebook 内使用命令行成功创建了 Docker 映像:

REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
sklearn               latest              01234212345        6 minutes ago       1.23GB
Run Code Online (Sandbox Code Playgroud)

但是当我在 Jupyter 中运行时:

! aws ecr create-repository --repository-name sklearn
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

An error occurred (AccessDeniedException) when calling the CreateRepository operation: User: arn:aws:sts::1234567:assumed-role/AmazonSageMaker-ExecutionRole-12345/SageMaker is not authorized to perform: ecr:CreateRepository on resource: *
Run Code Online (Sandbox Code Playgroud)

我已经为 EC2Container 设置了 SageMaker、EC2、EC2ContainerService 权限和以下策略,但仍然遇到相同的错误。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:*",
        "ec2:*"
      ],
      "Resource": "*"
    } …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services scikit-learn docker dockerfile amazon-sagemaker

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