小编yal*_*man的帖子

如何从 Keras 中的 ImageDataGenerator 格式化 X 和 Y 数据?

现在,我能够在我的图像数据上训练和测试神经网络。我希望能够从 DirectoryIterator train_generator 中提取图像数据和相应的标签,以便我可以对这些数据进行洗牌并执行交叉验证。有没有办法提取(如果需要,还可以格式化)这些数据?

from keras.preprocessing.image import ImageDataGenerator

img_width, img_height = 150, 150
train_data_dir = '/train'
datagen = ImageDataGenerator(rescale=1./255) #rescales [0,1]
train_generator = datagen.flow_from_directory(train_data_dir, target_size=(img_width, img_height), shuffle=True, batch_size=32, class_mode='binary')
#I want to do something like (X, Y) = train_generator.getData()
Run Code Online (Sandbox Code Playgroud)

python keras

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

为什么useState变量`const`在反应中?

我的理解是,在使用时useState(),我们应该这样声明数组:

const [someBooleanValue, setSomeBooleanValue] = useState(false)
Run Code Online (Sandbox Code Playgroud)

代替

let [someBooleanValue, setSomeBooleanValue] = useState(false)
Run Code Online (Sandbox Code Playgroud)

通常,const用于不会改变的变量。在这里,someBooleanValue将发生变化。const在这种情况下,发生了什么允许我们使用关键字?

javascript ecmascript-6 reactjs

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

根据当前时区与东部时区的时差更改LocalDateTime

假设一周前我生成一个2015-10-10T10:00:00的LocalDateTime.此外,我们假设我生成了当前的时区ID

TimeZone timeZone = TimeZone.getDefault();
String zoneId = timeZone.getId();  // "America/Chicago"
Run Code Online (Sandbox Code Playgroud)

我的zoneId是"America/Chicago".

有没有一种简单的方法可以将我的LocalDateTime转换为时区id"America/New_York"(即所以我更新的LocalDateTime将是2015-10-10T11:00:00)?

更重要的是,无论我在哪个时区,有没有办法可以将我的LocalDateTime转换为东部时间(即带有zoneId"America/New_York"的时区)?我特意寻找一种方法来处理过去生成的任何LocalDateTime对象,而不一定是当前时间.

java timezone datetime

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

如何在返回带有上下文参数的函数的函数中模拟 koa 上下文

我有一个文件,myFunction.ts定义并导出一个函数:

export function MyFunction() {
    return async (ctx: Koa.Context) => {
        //some work happens in here
    };
}
Run Code Online (Sandbox Code Playgroud)

该函数在 Koa 中间件文件中被调用,并继承了ctx之前的中间件。在这种情况下,如何创建一个模拟ctx来进行测试?MyFunction()

testing middleware mocking koa jestjs

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

测试Spring onApplicationEvent的简单方法

我有一个包含功能的应用程序事件监听器:

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
//do some stuff
}
Run Code Online (Sandbox Code Playgroud)

如何编写一个单元测试来模拟ContextRefreshedEvent(例如执行我的jar),并测试onApplicationEvent函数是否已完成应做的工作?

java junit spring unit-testing event-listener

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

使用fit()函数时,Scikit学习GaussianProcessClassifier内存错误

我有X_train和y_train作为2 numpy.ndarrays的大小分别为(32561,108)和(32561,)。

每次我调用适合GaussianProcessClassifier的函数时,都会收到内存错误。

>>> import pandas as pd
>>> import numpy as np
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import RBF
>>> X_train.shape
(32561, 108)
>>> y_train.shape
(32561,)
 >>> gp_opt = GaussianProcessClassifier(kernel=1.0 * RBF(length_scale=1.0))
>>> gp_opt.fit(X_train,y_train)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/retsim/.local/lib/python2.7/site-packages/sklearn/gaussian_process/gpc.py", line 613, in fit
    self.base_estimator_.fit(X, y)
  File "/home/retsim/.local/lib/python2.7/site-packages/sklearn/gaussian_process/gpc.py", line 209, in fit
    self.kernel_.bounds)]
  File "/home/retsim/.local/lib/python2.7/site-packages/sklearn/gaussian_process/gpc.py", line 427, in _constrained_optimization
    fmin_l_bfgs_b(obj_func, initial_theta, bounds=bounds)
  File "/home/retsim/anaconda2/lib/python2.7/site-packages/scipy/optimize/lbfgsb.py", line 199, in fmin_l_bfgs_b
    **opts) …
Run Code Online (Sandbox Code Playgroud)

python classification pandas scikit-learn sklearn-pandas

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

每次使用cross_val_score时如何洗牌?

在训练 Ridge 分类器时,我可以像这样执行 10 折交叉验证:

clf = linear_model.RidgeClassifier()
n_folds = 10
scores = cross_val_score(clf, X_train, y_train, cv=n_folds)
scores
array([0.83236107, 0.83937346, 0.84490172, 0.82985258, 0.84336609,
       0.83753071, 0.83753071, 0.84213759, 0.84121622, 0.84398034])
Run Code Online (Sandbox Code Playgroud)

如果我想再次执行 10 折交叉验证,我使用:

scores = cross_val_score(clf, X_train, y_train, cv=n_folds)
Run Code Online (Sandbox Code Playgroud)

我最终得到了相同的结果。

因此,似乎两次数据都以相同的方式拆分。有没有办法在每次执行交叉验证时将数据随机划分为 n_folds?

python scikit-learn cross-validation

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

如何使用 npm 的 csvtojson 将 csv 转换为 json 并忽略 csv 中的第一行?

我有一个这样的csv:

this is the first column, this is the 2nd,
firstVal,                 secondVal
david,                    baseball
jon,                      soccer
Run Code Online (Sandbox Code Playgroud)

我想将其转换为:

[{firstVal:david, secondVal:baseball},{firstVal:jon,secondVal:soccer}]
Run Code Online (Sandbox Code Playgroud)

我的 csv 中的第一行是元数据(基本上只是实际列标题的描述——firstVal 和 secondaryVal),我不想将其包含在 json 中。我试过了:

csvtojson({noheader: true}).fromFile(csvFilePath)//...
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。如何忽略第一行进行此转换?

javascript data-conversion npm csvtojson

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

检查元组的priorityQueue中是否存在元素

说我有这段代码:

q = PriorityQueue()
a = ((1,1), 10, 0)
b = ((2,2), 99, 200)
q.push(a, 1)
q.push(b, 2)
Run Code Online (Sandbox Code Playgroud)

我想检查元素(1,1)是否存在于队列中的任何元组中。有没有办法做到这一点?

python queue priority-queue

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