我使用 Keras2 和 TensorFlow 作为后端,并尝试将水平矩形图像(宽度:150 x 高度:100 x ch:3)输入网络。
我使用 cv2 来预处理图像,cv2 & TensorFlow 将图像的形状视为 [ height, width, ch ] 排序(在我的例子中,它是 [100, 150, 3]这种格式与(width:150 x height :100 x ch:3),但这不是错误。)
所以我将 Keras 模型 API 输入定义为以下代码,但出现错误。
img = cv2.imread('input/train/{}.jpg'.format(id))
img = cv2.resize(img, (100, 150))
inputs = Input(shape=(100, 150, 3))
x = Conv2D(8, (3, 3), padding='same', kernel_initializer='he_normal')(inputs)
~~~
Run Code Online (Sandbox Code Playgroud)
错误消息如下
ValueError: Error when checking input: expected input_4 to have shape
(None, 100, 150, 3) but got array with …
Run Code Online (Sandbox Code Playgroud) 我使用hyperopt来搜索SVM分类器的最佳参数,但Hyperopt说最好的'内核'是'0'.{'kernel':'0'}显然不合适.
有谁知道这是由我的错误还是一袋hyperopt造成的?
代码如下.
from hyperopt import fmin, tpe, hp, rand
import numpy as np
from sklearn.metrics import accuracy_score
from sklearn import svm
from sklearn.cross_validation import StratifiedKFold
parameter_space_svc = {
'C':hp.loguniform("C", np.log(1), np.log(100)),
'kernel':hp.choice('kernel',['rbf','poly']),
'gamma': hp.loguniform("gamma", np.log(0.001), np.log(0.1)),
}
from sklearn import datasets
iris = datasets.load_digits()
train_data = iris.data
train_target = iris.target
count = 0
def function(args):
print(args)
score_avg = 0
skf = StratifiedKFold(train_target, n_folds=3, shuffle=True, random_state=1)
for train_idx, test_idx in skf:
train_X = iris.data[train_idx]
train_y = iris.target[train_idx]
test_X = iris.data[test_idx] …
Run Code Online (Sandbox Code Playgroud) python machine-learning scikit-learn cross-validation hyperopt