我尝试在keras博客文章中运行代码。
该代码将写入.npy文件,如下所示:
bottleneck_features_train = model.predict_generator(generator, nb_train_samples // batch_size)
np.save(open('bottleneck_features_train.npy', 'w'),bottleneck_features_train)
Run Code Online (Sandbox Code Playgroud)
然后从该文件读取:
def train_top_model():
train_data = np.load(open('bottleneck_features_train.npy'))
Run Code Online (Sandbox Code Playgroud)
现在我得到一个错误,说:
Found 2000 images belonging to 2 classes.
Traceback (most recent call last):
File "kerasbottleneck.py", line 103, in <module>
save_bottlebeck_features()
File "kerasbottleneck.py", line 69, in save_bottlebeck_features
np.save(open('bottleneck_features_train.npy', 'w'),bottleneck_features_train)
File "/opt/anaconda3/lib/python3.6/site-packages/numpy/lib/npyio.py", line 511, in save
pickle_kwargs=pickle_kwargs)
File "/opt/anaconda3/lib/python3.6/site-packages/numpy/lib/format.py", line 565, in write_array
version)
File "/opt/anaconda3/lib/python3.6/site-packages/numpy/lib/format.py", line 335, in _write_array_header
fp.write(header_prefix)
TypeError: write() argument must be str, not bytes
Run Code Online (Sandbox Code Playgroud)
之后,我尝试将文件模式从“ w”更改为“ wb”。这导致在读取文件时出错: …
在Ubuntu中,OpenCV的imshow函数有一个窗口,其中可以使用不同的选项,例如放大、缩小、平移窗口等,如下所示:
然而,在 Windows 中,这些功能不存在。我有一个特殊的情况,我需要在 Windows 上部署我的 OpenCV 代码,用户需要放大图像的某些部分。
有没有办法在 Windows 中访问/添加这些功能?
我的数据帧 df 中有一个列,其中包含 float 和 str 类型的值:
df['ESTACD'].unique()
Output:
array([11.0, 32.0, 31.0, 35.0, 37.0, 84.0, 83.0, 81.0, 97.0, 39.0,
38.0, 40.0, 34.0, 7.0, 17.0, 16.0, 14.0, 82.0, 8.0, '11', '40',
'31', '39', '68', '97', '32', '33', '37', '38', '83', '84', '93',
'35', '81', '67', '07', '80', '71', 'A3', '14', '17', '22', '34',
'36', '82', '08'], dtype=object)
Run Code Online (Sandbox Code Playgroud)
我希望将此列的所有值转换为字符串类型。在这里使用astype(str)
是不够的,因为我们最终得到“11.0”、“32.0”等值。
我能想到的唯一其他方法是使用 for 循环:
for i in range(len(df)):
if (type(df['ESTACD'][i]) == float) or (df['ESTACD'][i].startswith('0')):
df['ESTACD'][i] = str(int(df['ESTACD'][i]))
Run Code Online (Sandbox Code Playgroud)
然而,这对于大型数据集来说非常耗时。有没有办法在没有循环的情况下实现这个?
我在代码的一部分中创建了一个数字,如下所示:
n = arange(51)
fig3 = plt.figure()
plt.semilogy(n,a1mag,'ro')
Run Code Online (Sandbox Code Playgroud)
现在,我想在代码的后面部分为此图添加另一个图.在绘图时有没有办法访问fig3?