小编use*_*814的帖子

GAN 的随机噪声

我是 GAN 新手。我正在学习对 GAN 进行建模来生成图像,但是我并不真正了解给予生成器的随机噪声到底是什么。它是从 0 到 1 的随机数吗?它的大小应该是多少。另外,每次发电机运行时随机噪声都应该恒定吗?

任何帮助,将不胜感激。

random machine-learning noise deep-learning generative-adversarial-network

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

运行时错误:张量 a (133) 的大小必须与非单维 1 处的张量 b (10) 的大小匹配

我正在训练一个 CNN 模型。我在为我的模型进行训练迭代时遇到了问题。代码如下:

class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()

        #convo layers
        self.conv1 = nn.Conv2d(3,32,3)
        self.conv2 = nn.Conv2d(32,64,3)
        self.conv3 = nn.Conv2d(64,128,3)
        self.conv4 = nn.Conv2d(128,256,3)
        self.conv5 = nn.Conv2d(256,512,3)

        #pooling layer
        self.pool = nn.MaxPool2d(2,2)

        #linear layers
        self.fc1 = nn.Linear(512*5*5,2048)
        self.fc2 = nn.Linear(2048,1024)
        self.fc3 = nn.Linear(1024,133)

        #dropout layer
        self.dropout = nn.Dropout(0.3)
        def forward(self, x):
        #first layer
        x = self.conv1(x)
        x = F.relu(x)
        x = self.pool(x)
        #x = self.dropout(x)
        #second layer
        x = self.conv2(x)
        x = F.relu(x)
        x = self.pool(x)
        #x = self.dropout(x)
        #third layer …
Run Code Online (Sandbox Code Playgroud)

python-3.x conv-neural-network pytorch

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

如何在训练 CNN 时为 nn.Linear 层选择参数?

我正在尝试训练 CNNFashion-MNIST使用Conv2dMaxpoolLinear层对数据中的图像进行分类。我in_features = 12*4*4nn.Linear层中遇到了如下所述的代码。

我能否获得有关如何in_features为 nn.Linear 层选择参数的帮助?

class Network(nn.Module):
    def __init__(self):
        super(Network, self).__init__()
        self.conv1 = nn.Conv2d(in_channels=1, out_channels=6, kernel_size=5)
        self.conv2 = nn.Conv2d(in_channels=6, out_channels=12, kernel_size=5)

        self.fc1 = nn.Linear(in_features=12*4*4, out_features=120)
        self.fc2 = nn.Linear(in_features=120, out_features=60)
        self.out = nn.Linear(in_features=60, out_features=10)
Run Code Online (Sandbox Code Playgroud)

python-3.x conv-neural-network pytorch

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

无法在 Pyspark 中执行用户定义的函数 RegexTokenizer

我正在尝试使用 Pyspark 使用数据中的文本特征执行文本分类。下面是我的文本预处理代码,该代码未能执行用户定义的函数 RegexTokenizer。

    tokenizer = RegexTokenizer(inputCol = "text", outputCol = "words", pattern = "\\W")
    add_stopwords = StopWordsRemover.loadDefaultStopWords("english")
    remover = StopWordsRemover(inputCol = "words", outputCol = "filtered").setStopWords(add_stopwords)
    label_stringIdx = StringIndexer(inputCol = "label", outputCol = "target")
    countVectors = CountVectorizer(inputCol="filtered", outputCol="features", vocabSize=1000, minDF=5)
    #pipleline for text pre-processing
    pipeline = Pipeline(stages=[tokenizer,remover, countVectors, label_stringIdx])

    #fit the dat for the pipeline
    pipelineFit = pipeline.fit(dataset)
    dataset = pipelineFit.transform(dataset)
    dataset.show()
Run Code Online (Sandbox Code Playgroud)

错误是:

/usr/local/lib/python3.6/dist-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
    326                 raise Py4JJavaError(
    327                     "An error occurred while calling {0}{1}{2}.\n".
--> …
Run Code Online (Sandbox Code Playgroud)

text apache-spark-sql pyspark apache-spark-ml apache-spark-mllib

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

MNIST 数据分类不适用于 Google Colab

我正在尝试在 Google colab 上使用深度 MLP 训练 MNIST 数字数据集。我重新调整了输入并进行了数据预处理。模型代码如下:

    #define the model layers
    model = Sequential()
    model.add(Dense(512, input_shape = input_shape, activation = "relu"))
    model.add(Dense(256, activation = "relu"))
    model.add(Dropout(0.1))
    model.add(Dense(128,activation = "relu"))
    model.add(Dense(64,activation = "relu"))
    model.add(Dropout(0.1))
    model.add(Flatten())
    model.add(Dense(tar_class,activation = "sigmoid"))

    model.compile(optimizer = "adam",
          loss = "categorical_crossentropy",
          metrics = ["accuracy"])

    model.summary()

    history = model.fit(X_train,y_train,
                epochs = 10,
                validation_split = 0.1,
                batch_size = 64,
                verbose = True)
Run Code Online (Sandbox Code Playgroud)

当我运行 model.fit 代码时,仅对数据集中的 844 个样本进行训练,而不是对 60000 个样本进行训练。不过,这段代码在我本地的 jupyter 笔记本中运行良好。我想在 Colab 上工作,这样我就可以使用 GPU 来训练模型,这比我的本地机器更快。

有人可以帮我吗?

python neural-network keras google-colaboratory

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