我正在学习深度学习.训练了图像分类算法.然而,问题是训练我使用的图像:
test_image = image.load_img('some.png', target_size = (64, 64))
test_image = image.img_to_array(test_image)
Run Code Online (Sandbox Code Playgroud)
在实际应用中,我使用:
test_image = cv2.imread('trick.png')
test_image = cv2.resize(test_image, (64, 64))
Run Code Online (Sandbox Code Playgroud)
但我发现那些给出了不同的ndarray(不同的数据):
load_image的最后一个条目:
[ 64. 71. 66.]
[ 64. 71. 66.]
[ 62. 69. 67.]]]
Run Code Online (Sandbox Code Playgroud)
来自cv2.imread的最后条目:
[ 15 23 27]
[ 16 24 28]
[ 14 24 28]]]
Run Code Online (Sandbox Code Playgroud)
,所以系统无法正常工作.有没有办法将结果相互匹配?
我需要使用Google Vision API识别图像.在这些例子中,他们使用以下结构:
with io.open('test.png', 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
Run Code Online (Sandbox Code Playgroud)
我需要做类似的事,但我的形象来自:
content = cv2.imread()
Run Code Online (Sandbox Code Playgroud)
哪个返回numpy数组,而不是字节.我试过了:
content = content.tobytes()
Run Code Online (Sandbox Code Playgroud)
它将数组转换为字节,但显然返回不同的字节,因为它给出了不同的结果.
那么如何使我的图像数组类似于我通过open()
函数得到的图像数组
我想创建颜色映射,定义一些颜色名称和这些颜色应该落在的范围内的边界。例如(BGR格式),
colors = {
'red': ((0, 0, 255), (125, 125, 255)),
'blue': ((255, 0, 0), (255, 125, 125)),
'yellow' ....
}
Run Code Online (Sandbox Code Playgroud)
所以如果我收到颜色,假设 (255, 50, 119) 我可以称之为蓝色。我想至少为彩虹加上灰色,黑色,白色的颜色制作这样的映射。使用 Python 和 openCV。
问题是我真的不明白从哪里获得这些边界值,蓝色、红色等是否有最低/最高值?
我有这样的 HTML:
<a id="buttonToUpload" class="btn-pink medium" href="#">
<span class="icon-arrow-right">upload photo</span>
</a>
<form id="form1" enctype="multipart/form-data">
<input id="uploadImage" type="file" accept="image/png, image/gif, image/jpeg, image/jpg" style="visibility: hidden">
</form>
Run Code Online (Sandbox Code Playgroud)
按提升系统对话框选择文件,我无法通过 webdriver 访问。我尝试直接使用 send_keys() 但它引发了 ElementNotVisibleException。那么如何在那里上传照片呢?实际代码:
driver = webdriver.Firefox()
driver.get('http://www........')
upload_input = driver.find_element_by_id('uploadImage')
upload_input.send_keys(os.getcwd()+'/image.jpg')
Run Code Online (Sandbox Code Playgroud) 我有这些模型:
class UserProfile(models.Model):
name = models.CharField(max_length=100)
class Dialog(models.Model):
belong_to = models.ManyToManyField(UserProfile)
class Message(models.Model):
# Dialog to which this message belongs
part_of = models.ForeignKey(Dialog)
# User who sends message
sender = models.ForeignKey(UserProfile, related_name='sender')
# User who receives message
receiver = models.ForeignKey(UserProfile, related_name='receiver')
Run Code Online (Sandbox Code Playgroud)
我想要做的是限制发送方和接收方字段的选择,以便它们只能是整个对话框所属的用户.我试过这个:
sender = models.ForeignKey(UserProfile,
related_name='sender',
limit_choices_to={'dialog':1})
Run Code Online (Sandbox Code Playgroud)
这限制了选择,但仅限于id = 1的对话框成员.我想知道这是否可以动态完成?
我正在学习ML并完成波士顿房价预测的任务。我有以下代码:
from sklearn.metrics import fbeta_score, make_scorer
from sklearn.model_selection import GridSearchCV
def fit_model(X, y):
""" Tunes a decision tree regressor model using GridSearchCV on the input data X
and target labels y and returns this optimal model. """
# Create a decision tree regressor object
regressor = DecisionTreeRegressor()
# Set up the parameters we wish to tune
parameters = {'max_depth':(1,2,3,4,5,6,7,8,9,10)}
# Make an appropriate scoring function
scoring_function = make_scorer(fbeta_score, beta=2)
# Make the GridSearchCV object
reg = GridSearchCV(regressor, param_grid=parameters, scoring=scoring_function)
print …
Run Code Online (Sandbox Code Playgroud) python machine-learning decision-tree scikit-learn grid-search
假设我有一个数据帧:
date | brand | color
--------------------
2017 | BMW | red
2017 | GM | blue
2017 | BMW | blue
2017 | BMW | red
2018 | BMW | green
2018 | GM | blue
2018 | GM | blue
2018 | GM | red
Run Code Online (Sandbox Code Playgroud)
结果我希望有类似的东西:
date | brand | red | blue | green
---------------------------------
2017 | BMW | 2 | 1 | 0
| GM | 0 | 1 | 0
2018 | BMW | 0 …
Run Code Online (Sandbox Code Playgroud) 假设我有一个像这样的 Django 模型。
class Car(models.Model):
speed = models.IntegerField()
color = models.CharField(max_length=120)
Run Code Online (Sandbox Code Playgroud)
我通过管理员在管理员中注册了它
admin.site.register(Car)
Run Code Online (Sandbox Code Playgroud)
我想为管理站点对象视图添加自定义 JS 按钮,它将警告汽车模型实例的颜色值。所以当我按下它时,我会得到类似“ID 为13的汽车是红色的”这样的信息
如何通过 JavaScript 获取对象的 id 和颜色字段的值?
python ×6
opencv ×3
python-3.x ×3
django ×2
numpy ×2
colors ×1
django-admin ×1
foreign-keys ×1
grid-search ×1
javascript ×1
keras ×1
pandas ×1
reactjs ×1
scikit-learn ×1
selenium ×1