【发布时间】:2023-04-10 03:51:01
【问题描述】:
当我想使用 image_load() 加载图像时,我得到了这个错误预期的 str、字节或 os.PathLike 对象,而不是 ImageFieldFile。这是我的代码
from django.db import models
from keras.preprocessing.image import load_img, img_to_array
from keras.preprocessing import image
import numpy as np
# Create your models here.
class Image(models.Model):
picture = models.ImageField(upload_to='article_images')
classified = models.CharField(max_length=200, blank=True)
uploaded = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.classified
def save(self, *args, **kwargs):
img = load_img(self.picture, target_size=(224, 224))
img_arr = img_to_array(img)
to_pred = np.expand_dims(img_arr, axis=0) # (1,299,299,3)
print(to_pred.shape)
super().save(*args, **kwargs)
错误: 预期的 str、字节或 os.PathLike 对象,而不是 ImageFieldFile
【问题讨论】:
-
你解决了吗?
-
是的,解决了。你可以在我的 github 上查看这个项目,这里是link
-
究竟如何?出了什么问题?
-
你能解释一下你是怎么解决这个问题的吗?