我使用以下代码将字符串标签列表映射到单热编码值列表:
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import OneHotEncoder
labelEncoder = LabelEncoder()
targets = ["blue","green","blue","blue","green"]
integerEncoded = labelEncoder.fit_transform(targets)
Run Code Online (Sandbox Code Playgroud)
在稍后的阶段,我需要确切地知道哪些字符串标签映射到哪些整数值。
即我需要这样的东西:
integerMapping = GetIntegerMapping(labelEncoder)
Run Code Online (Sandbox Code Playgroud)
在哪里
integerMapping["blue"]
Run Code Online (Sandbox Code Playgroud)
应该返回所有“蓝色”标签映射到的 int 值
和
integerMapping["green"]
Run Code Online (Sandbox Code Playgroud)
应该返回所有“绿色”标签映射到的 int 值。
我怎样才能得到那个integerMapping字典?
以下代码是一个更大函数的片段,该函数在 3 个轴上绘制多个财务指标:
left, width = 0.1, 0.8
rect1 = [left, 0.7, width, 0.2]
rect2 = [left, 0.3, width, 0.4]
rect3 = [left, 0.1, width, 0.2]
fig = plt.figure(facecolor='white')
axescolor = '#f6f6f6' # the axes background color
ax1 = fig.add_axes(rect1)#, axisbg=axescolor) # left, bottom, width, height
ax2 = fig.add_axes(rect2,sharex=ax1)#, axisbg=axescolor)
ax3 = fig.add_axes(rect3,sharex=ax1)#, axisbg=axescolor
Run Code Online (Sandbox Code Playgroud)
最终的情节如下所示:
现在我想添加背景矩形,其高度覆盖整个 x 轴(即所有轴),宽度为几分钟,如下所示:
我怎样才能做到这一点?
我有一个(简化的)函数Foo
template<typename It, typename T>
void Foo(It begin, It end, T&& CallBar)
{
CallBar(begin, end);
}
Run Code Online (Sandbox Code Playgroud)
另一个简化的功能吧
template<typename It>
It Bar(It begin, It end)
{
return begin;
}
Run Code Online (Sandbox Code Playgroud)
当我以下列方式调用这两个函数时
std::vector<int> v{ 3, 8, 2, 5, 1, 4, 7, 6 };
Foo(v.begin(), v.end(), Bar);
Run Code Online (Sandbox Code Playgroud)
我收到了错误
'声明':无法推断'标识符'的模板参数
还有什么我需要指定才能编译?
我找到以下代码片段来可视化已保存到*.pb文件中的模型:
model_filename ='saved_model.pb'
with tf.Session() as sess:
with gfile.FastGFile(path_to_model_pb, 'rb') as f:
data = compat.as_bytes(f.read())
sm = saved_model_pb2.SavedModel()
sm.ParseFromString(data)
g_in = tf.import_graph_def(sm.meta_graphs[0].graph_def)
LOGDIR='.'
train_writer = tf.summary.FileWriter(LOGDIR)
train_writer.add_graph(sess.graph)
Run Code Online (Sandbox Code Playgroud)
现在,我正在努力创建saved_model.pb。如果我的session.run看起来像这样:
_, cr_loss = sess.run([train_op,cross_entropy_loss],
feed_dict={input_image: images,
correct_label: gt_images,
keep_prob: KEEP_PROB,
learning_rate: LEARNING_RATE}
)
Run Code Online (Sandbox Code Playgroud)
我如何保存图形所含train_op到saved_model.pb?
该物体检测笔记本演示,如何预先训练和冷冻tensorflow模型可以用来检测测试图像的对象。
在此通知中,功能
from utils import visualization_utils as vis_util
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
Run Code Online (Sandbox Code Playgroud)
输出测试图像,其中在检测到的对象周围绘制框。
如何使用此功能仅绘制特定类别的框,而不是category_index集合中所有类别的框?即,如何获得此功能以仅在模型确定其为例如汽车的对象周围绘制框?
json结构
{
"categories": [{
"supercategory": "Bottle",
"id": 1,
"name": "Bottle"
},
{
"supercategory": "Car",
"id": 2,
"name": "Car"
}]
}
Run Code Online (Sandbox Code Playgroud)
由以下python脚本读取:
with open('file.json') as json_data:
json_info = json.load(json_data)
Run Code Online (Sandbox Code Playgroud)
稍后,同一脚本尝试以下列方式访问数据结构:
json_info['1']['name']
json_info['2']['name']
Run Code Online (Sandbox Code Playgroud)
数字指的是json结构中的"id"字段.由于该代码显然与json结构不一致:我如何更改json结构以使其工作?(假设我无法更改脚本).
怎么能查字典
class Foo:
def __init__(self,value):
self.property = value
dictionary = {"one":Foo(1),
"two":Foo(2)}
Run Code Online (Sandbox Code Playgroud)
以降序排序,按Foo对象的self.property?
哪种 C++ 类型足够大以表示 64 位十进制数,例如
3141592653589793238462643383279502884197169399375105820974944592
代码段
std::vector<int> v{ 3, 8, 2, 5, 1, 4, 7, 6};
Partition(v.begin(), v.end(), v.begin());
Run Code Online (Sandbox Code Playgroud)
应重新排列向量v,使前n个元素小于或等于3,后面的元素大于3.结果向量应如下所示:
1,2,3,5,8,4,7,6
如何测试Partition是否在断言声明以下内容的断言语句中生成正确的结果:
断言向量的第一部分仅包含小于或等于x的元素,而秒部分仅包含大于x的元素
?
我有一个模板化的函数,它根据调用者指定的算法选择一个向量或列表元素:
template<typename It>
void Foo(It begin, It end, std::function<It(It, It)> GetElement)
{
It element = GetElement(begin, end);
}
Run Code Online (Sandbox Code Playgroud)
如何使用lambda表达式调用此函数?
我的第一个方法是
Foo(v.begin(),
v.end(),
[v](? , ? ) {return v.begin(); });
Run Code Online (Sandbox Code Playgroud)
但是,我顽固地陷入争论的一部分,这是由问号所标志的......
python ×5
c++ ×4
templates ×2
tensorflow ×2
bigint ×1
dictionary ×1
json ×1
matplotlib ×1
python-3.x ×1
scikit-learn ×1
sorting ×1
vector ×1