使用ResNet50预训练的权重我正在尝试构建一个分类器.代码库完全在Keras高级Tensorflow API中实现.完整的代码发布在下面的GitHub链接中.
预训练模型的文件大小为94.7mb.
我加载了预先训练好的文件
new_model = Sequential()
new_model.add(ResNet50(include_top=False,
pooling='avg',
weights=resnet_weight_paths))
Run Code Online (Sandbox Code Playgroud)
并适合模型
train_generator = data_generator.flow_from_directory(
'path_to_the_training_set',
target_size = (IMG_SIZE,IMG_SIZE),
batch_size = 12,
class_mode = 'categorical'
)
validation_generator = data_generator.flow_from_directory(
'path_to_the_validation_set',
target_size = (IMG_SIZE,IMG_SIZE),
class_mode = 'categorical'
)
#compile the model
new_model.fit_generator(
train_generator,
steps_per_epoch = 3,
validation_data = validation_generator,
validation_steps = 1
)
Run Code Online (Sandbox Code Playgroud)
在训练数据集中,我有两个文件夹狗和猫,每个持有近10,000张图像.当我编译脚本时,我收到以下错误
Epoch 1/1 2018-05-12 13:04:45.847298:W tensorflow/core/framework/allocator.cc:101] 38535168的分配超过系统内存的10%.2018-05-12 13:04:46.845021:W tensorflow/core/framework/allocator.cc:101] 37171200的分配超过系统内存的10%.2018-05-12 13:04:47.552176:W tensorflow/core/framework/allocator.cc:101] 37171200的分配超过系统内存的10%.2018-05-12 13:04:48.199240:W tensorflow/core/framework/allocator.cc:101] 37171200的分配超过系统内存的10%.2018-05-12 13:04:48.918930:W tensorflow/core/framework/allocator.cc:101] 37171200的分配超过系统内存的10%.2018-05-12 13:04:49.274137:W tensorflow/core/framework/allocator.cc:101] 19267584的分配超过系统内存的10%.2018-05-12 13:04:49.647061:W tensorflow/core/framework/allocator.cc:101] 19267584的分配超过系统内存的10%.2018-05-12 …
我需要获取存储在Google Bucket中的文件信息。信息,如文件大小,存储类,最后修改,类型。我搜索了google文档,但是可以通过curl或console方法来完成。我需要从Python API获得该信息,例如下载blob,将blob上传到存储桶。示例代码或任何帮助表示赞赏!
我正在做文档分类并获得了高达 76% 的准确率。在预测文档类别时,我遵循了一个
doc_clf.predict(tf_idf.transform((count_vect.transform([r'document']))))
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
File "/usr/local/lib/python3.5/dist- packages/sklearn/utils/metaestimators.py", line 115, in <lambda>
out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/sklearn/pipeline.py", line 306, in predict
Xt = transform.transform(Xt)
File "/usr/local/lib/python3.5/dist-packages/sklearn/feature_extraction/text.py", line 923, in transform
_, X = self._count_vocab(raw_documents, fixed_vocab=True)
File "/usr/local/lib/python3.5/dist-packages/sklearn/feature_extraction/text.py", line 792, in _count_vocab
for feature in analyze(doc):
File "/usr/local/lib/python3.5/dist-packages/sklearn/feature_extraction/text.py", line 266, in <lambda>
tokenize(preprocess(self.decode(doc))), stop_words)
File "/usr/local/lib/python3.5/dist-packages/sklearn/feature_extraction/text.py", line 232, in <lambda>
return lambda x: strip_accents(x.lower())
File "/usr/local/lib/python3.5/dist-packages/scipy/sparse/base.py", line 647, in __getattr__
raise AttributeError(attr + " not found") …Run Code Online (Sandbox Code Playgroud) 我正在做图像分类,我训练了一个模型并保存了一个模型。当我尝试预测模型时,它显示输入错误。我正在使用 ResNet 架构构建一个分类器,最初将 input_size 声明为224 x 224。现在我需要预测测试图像的类别。
我将图像转换为224x224 numpy array。当我尝试以下代码时
#plot the figure
fig = plt.figure()
for num,data in enumerate(test_data):
img_num = data[1]
img_data = data[0]
y = fig.add_subplot(9,3,num+1)
orig = img_data
data = img_data.reshape(1,IMG_SIZ,IMG_SIZ,3)
#predict the model
model_out = model.predict_classes([orig])[0]
if np.argmax(model_out) == 1: str_label='Dog'
else: str_label='Cat'
y.imshow(orig,cmap = 'gray')
plt.title(str_label)
y.axes.get_xaxis().set_visible(False)
y.axes.get_yaxis().set_visible(False)
plt.show()
plt.savefig('test_labeled.jpg')
Run Code Online (Sandbox Code Playgroud)
它向我显示以下错误
ValueError:无法将大小为 50176 的数组重塑为形状 (1,224,224,3)
我必须以什么尺寸重塑正确的尺寸?
谢谢!
python ×2
python-3.x ×2
resnet ×2
tensorflow ×2
keras ×1
keras-layer ×1
memory ×1
scikit-learn ×1
stochastic ×1