目前,在使用Keras训练图像数据时,我正在处理一个大数据问题。我的目录中有一批.npy文件。每批包含512张图像。每个批次的对应标签文件均为.npy。看起来像:{image_file_1.npy,label_file_1.npy,...,image_file_37.npy,label_file_37}。每个图像文件都具有尺寸(512, 199, 199, 3),每个标签文件都具有尺寸(512, 1)(即1或0)。如果我将所有图像加载到一个ndarray中,则将超过35 GB。到目前为止,已阅读所有Keras Doc。我仍然找不到如何使用自定义生成器进行训练的方法。我已经阅读过flow_from_dict,ImageDataGenerator(...).flow()但是在那种情况下它们并不理想,或者我不知道如何定制它们。
import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.optimizers import SGD
from keras.preprocessing.image import ImageDataGenerator
val_gen = ImageDataGenerator(rescale=1./255)
x_test = np.load("../data/val_file.npy")
y_test = np.load("../data/val_label.npy")
val_gen.fit(x_test)
model = Sequential()
...
model_1.add(layers.Dense(512, activation='relu'))
model_1.add(layers.Dense(1, activation='sigmoid'))
model.compile(loss='categorical_crossentropy',
optimizer=sgd,
metrics=['acc'])
model.fit_generator(generate_batch_from_directory() # should give 1 image file and 1 label file
validation_data=val_gen.flow(x_test,
y_test,
batch_size=64),
validation_steps=32) …Run Code Online (Sandbox Code Playgroud) 我可以读取文件中没有列标题的 csv 文件。通过以下代码在 Rust 中使用极坐标:
use polars::prelude::*;
fn read_wine_data() -> Result<DataFrame> {
let file = "datastore/wine.data";
CsvReader::from_path(file)?
.has_header(false)
.finish()
}
fn main() {
let df = read_wine_data();
match df {
Ok(content) => println!("{:?}", content.head(Some(10))),
Err(error) => panic!("Problem reading file: {:?}", error)
}
}
Run Code Online (Sandbox Code Playgroud)
但现在我想在读取时或读取后将列名添加到数据框中,如何添加列名。这是一个列名称向量:
let COLUMN_NAMES = vec![
"Class label", "Alcohol",
"Malic acid", "Ash",
"Alcalinity of ash", "Magnesium",
"Total phenols", "Flavanoids",
"Nonflavanoid phenols",
"Proanthocyanins",
"Color intensity", "Hue",
"OD280/OD315 of diluted wines",
"Proline"
];
Run Code Online (Sandbox Code Playgroud)
如何将这些名称添加到数据框中。可以通过以下代码下载数据:
wget https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data
Run Code Online (Sandbox Code Playgroud) 我是 cmd 的新手。我创建了一个文件来创建文件夹和子文件夹。我放了一些timeout。第一个timeout正在工作,但其他超时不起作用不知道为什么。是不是因为改了path. 我已在 CMD 中逐行检查。在 CMD 中它工作正常。
输入:
timeout /t 5
@echo off
set path=C:\Users\bruce\Documents\Project-Gallary
cd %path%
@echo "Welcome master Bruce !"
@echo "Recommended Project Folder Name: G01-Global-Report/C01-Compliance"
echo %PATH%
timeout /t 10
@echo " *** Try not the put space in Folder Name"
set /p ProjectName="What is the project name? "
Run Code Online (Sandbox Code Playgroud)
输出:
C:\Users\bruce\Desktop>timeout /t 5
Waiting for 0 seconds, press a key to continue ...
"Recommended Project Folder Name: G01-Global-Report/C01-Compliance"
C:\Users\bruce\Documents\Project-Gallary
'timeout' …Run Code Online (Sandbox Code Playgroud)