小编use*_*476的帖子

Keras model.summary()结果 - 理解参数数量

我有一个简单的NN模型,用于检测使用Keras(Theano后端)在python中编写的28x28px图像的手写数字:

model0 = Sequential()

#number of epochs to train for
nb_epoch = 12
#amount of data each iteration in an epoch sees
batch_size = 128

model0.add(Flatten(input_shape=(1, img_rows, img_cols)))
model0.add(Dense(nb_classes))
model0.add(Activation('softmax'))
model0.compile(loss='categorical_crossentropy', 
         optimizer='sgd',
         metrics=['accuracy'])

model0.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch,
      verbose=1, validation_data=(X_test, Y_test))

score = model0.evaluate(X_test, Y_test, verbose=0)

print('Test score:', score[0])
print('Test accuracy:', score[1])
Run Code Online (Sandbox Code Playgroud)

运行良好,我的准确度达到了90%.然后,我执行以下命令,通过执行操作获取网络结构的摘要print(model0.summary()).这输出如下:

Layer (type)         Output Shape   Param #     Connected to                     
=====================================================================
flatten_1 (Flatten)   (None, 784)     0           flatten_input_1[0][0]            
dense_1 (Dense)     (None, 10)       7850        flatten_1[0][0]                  
activation_1        (None, 10)          0           dense_1[0][0] …
Run Code Online (Sandbox Code Playgroud)

python machine-learning neural-network theano keras

42
推荐指数
4
解决办法
6万
查看次数

N选择列表的N/2个子列表

在Python中是否有一种有效的方法可以将大小列表的所有分区n分成两个大小的子集n/2?我想获得一些迭代构造,使得每次迭代提供原始列表的两个非重叠子集,每个子​​集具有大小n/2.

例如:

A = [1,2,3,4,5,6]    # here n = 6
# some iterative construct
    # in each iteration, a pair of subsets of size n/2
    # subsets = [[1,3,4], [2,5,6]] for example for one of the iterations
    # subsets = [[1,2,5],[3,4,6]] a different iteration example
Run Code Online (Sandbox Code Playgroud)

子集应该是非重叠的,例如[[1,2,3], [4,5,6]]有效但[[1,2,3], [3,4,5]]不是.两个子集的顺序无关紧要,例如[[1,2,3], [4,5,6]]不计为不同[[4,5,6], [1,2,3]],因此这两个子集中只有一个应该出现在迭代中.每个子集内的顺序也无所谓,所以[[1,2,3], [4,5,6]],[[1,3,2], [4,5,6]],[[3,2,1], [6,5,4]],等一切算相同,所以只有其中一人应在整个迭代显示.

python list permutation combinatorics

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

使用dirent.h在C中实现ls程序

我正在尝试使用dirent库实现ls程序.看来我的DIR*mydir是<unspecified type>我用gdb调试的时候,它告诉我,好像我没有正确包含dirent.h头,但我相信我正确地包含了所有必需的头文件.

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/types.h> 
#include <sys/stat.h>

//Specifies whether or not to print hidden files
#define PRINT_HIDDEN 0

void readDirectory(char *dirString[]);

int main(int argc,char* argv[]) 
{
if(argc!=2)
{
printf("Usage: ./ls <directory>\n");
}

readDirectory(argv);    

return 0;
}

void readDirectory(char *dirString[])    
{
DIR *mydir; 
struct dirent *entry;
//Opening the directory and checking if valid
mydir = opendir(dirString[1]);  

if(mydir==NULL){
fprintf(stderr,"ls: cannot access %s: No such file or directory\n",
  dirString);
exit(EXIT_FAILURE);
}   
//Printing directories/files in specified directory …
Run Code Online (Sandbox Code Playgroud)

c ls dirent.h

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