我以以下方式构造了数据集:
dataset/train/0/456.jpg
dataset/train/1/456456.jpg
dataset/train/2/456.jpg
dataset/train/...
dataset/val/0/878.jpg
dataset/val/1/234.jpg
dataset/val/2/34554.jpg
dataset/val/...
Run Code Online (Sandbox Code Playgroud)
所以我torchvision.datasets.ImageFolder以前将数据集导入PyTorch。但是,似乎没有为正确的图像提供正确的标签。我在下面添加了我的代码:
data_transforms = {
'train': transforms.Compose(
[transforms.Resize((176,176)),
transforms.RandomRotation((0,360)),
transforms.RandomHorizontalFlip(),
transforms.RandomVerticalFlip(),
transforms.CenterCrop(128),
transforms.Grayscale(),
transforms.ToTensor(),
transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5))
]),
'val': transforms.Compose(
[transforms.Resize((128,128)),
transforms.Grayscale(),
transforms.ToTensor(),
transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5))
]),
}
data_dir = 'dataset'
image_datasets = {x: datasets.ImageFolder(os.path.join(data_dir, x),
data_transforms[x])
for x in ['train', 'val']}
dataloaders = {x: torch.utils.data.DataLoader(image_datasets[x], batch_size=4,
shuffle=True, num_workers=4)
for x in ['train', 'val']}
dataset_sizes = {x: len(image_datasets[x]) for x in ['train', 'val']}
class_names = image_datasets['train'].classes
device = torch.device("cuda:0" if torch.cuda.is_available() else …Run Code Online (Sandbox Code Playgroud) 因此,根据这个答案,最好不要迭代 Pandas DataFrame 中的行。但是,我不知道如何在不使用 for 循环的情况下解决我的问题。
我需要检测特定列中的任何连续重复(三次或多次)。因此,例如,如果某个特定 ID 的值 0 出现在连续三行中,我想知道该 ID。
ID Value
1 0
1 0.5
1 0 <--- I need this ID, because there are three consecutive 0s.
1 0
1 0
1 0.2
2 0.1
2 0 <--- Not this one! It only appears twice in a row for this ID.
2 0
3 0
3 0
Run Code Online (Sandbox Code Playgroud)
也许值得一提的是,这是一个时间序列,因此顺序至关重要。
当按下按钮时,我似乎无法完成将字符串传递给控制器的这个非常简单的任务。接收到的数据始终为空。有人能告诉我我做错了什么吗?
形式:
<form>
<div class="form-group">
<label for="ProcessName" class="control-control">Process Name</label>
<input id="ProcessName" class="form-control" placeholder="Choose process name">
<small id="subtitle" class="form-text text-muted">Text under input field.</small>
</div>
<button type="submit" class="btn btn-primary" id="addElement">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
Javascript:
$(function () {
$("#addElement").click(function () {
var processName = $("#ProcessName").val();
// I've tried this method
$.post('@Url.Action("AddProcessName")', processName, function (data, status) {
alert(data)
});
// And also this one, but both of them don't work.
// I did not try them at the same time, of course
$.ajax({
type: "POST",
url: …Run Code Online (Sandbox Code Playgroud) python ×2
ajax ×1
asp.net ×1
asp.net-mvc ×1
jquery ×1
pandas ×1
pytorch ×1
razor ×1
torchvision ×1