我无法解决此错误。此代码取自https://becoming human.ai/extract-a-feature-vector-for-any-image-with-pytorch-9717561d1d4c
import torch
import torch.nn as nn
import torchvision.models as models
import torchvision.transforms as transforms
from torch.autograd import Variable
from PIL import Image
pic_one = '/content/drive/My Drive/Video_Recommender/zframe1.jpg'
pic_two = '/content/drive/My Drive/Video_Recommender/zframe2.jpg'
model = models.resnet18(pretrained=True)
layer = model._modules.get('avgpool')
scaler = transforms.Scale((224, 224))
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
to_tensor = transforms.ToTensor()
def get_vector(image_name):
# 1. Load the image with Pillow library
img = Image.open(image_name)
# 2. Create a PyTorch Variable with the transformed image
t_img = Variable(normalize(to_tensor(scaler(img))).unsqueeze(0)) …Run Code Online (Sandbox Code Playgroud) machine-learning image-processing neural-network deep-learning
我有一个 Nestjs 服务器,并且已经上传了图像,但是当我尝试访问这些图像时,它们是一堆无法解释为图像的东西。(我还尝试将它们转换为 blob,然后将其转换为 objectURL,然后将其设置为 img 标签的 src 但这也不起作用)。上传代码:
@Post('upload')
@UseInterceptors(FileInterceptor('file',{
storage: diskStorage({
destination: './uploads',
filename: editFileName,
}),
fileFilter: imageFileFilter,
}))
uploadFile(@UploadedFile() file){
console.log(file);
file.filename = file.originalname;
const response = {
originalname: file.originalname,
filename: file.filename,
}
return response;
}
Run Code Online (Sandbox Code Playgroud)
上面的上传代码完美地将图像保存为我的上传文件夹中的index-53a2.jpg。现在尝试使用 get req 获取图像:
@Get()
display(@Res() res){
res.sendFile('index-53a2.jpg',{ root: './uploads' })
}
Run Code Online (Sandbox Code Playgroud)
对此的记录响应它给出了一些不可读(可能是编码的)内容的字符串。
我用于测试的代码:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('#abc').on('submit', function (e) {
e.preventDefault();
$.ajax({
url: 'http:/localhost:3000/student/upload',
method:'POST',
data: new FormData(this),
contentType: false,
cache:false,
processData:false,
success: function (data) …Run Code Online (Sandbox Code Playgroud) 我无法在 PErl 中安装 GD 模块。我已经完成了 CPAN GD 但这给了我错误:
Reading '/home/harsh/.cpan/Metadata'
Database was generated on Mon, 28 Sep 2020 02:17:03 GMT
Running install for module 'GD'
Checksum for /home/harsh/.cpan/sources/authors/id/R/RU/RURBAN/GD-2.73.tar.gz ok
'YAML' not installed, will not store persistent state
Configuring R/RU/RURBAN/GD-2.73.tar.gz with Makefile.PL
Notice: Type perl Makefile.PL -h for command-line option summary.
Package gdlib was not found in the pkg-config search path.
Perhaps you should add the directory containing `gdlib.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gdlib' found
at Makefile.PL line …Run Code Online (Sandbox Code Playgroud)