我只是编写一个通用对象工厂并使用boost预处理器元库来创建一个可变参数模板(使用2010并且它不支持它们).我的函数使用rval引用并std::forward进行完美的转发,它让我思考...当C++ 0X出来并且我有一个标准编译器时,我会使用真正的可变参数模板.但是,我怎么称呼std::forward这些论点?
template <typename ...Params>
void f(Params... params) // how do I say these are rvalue reference?
{
y(std::forward(...params)); //? - I doubt this would work.
}
Run Code Online (Sandbox Code Playgroud)
我能想到的唯一方法就是需要手动拆包... params,我也不是那里.是否有更快的语法可行?
c++ rvalue-reference variadic-templates perfect-forwarding c++11
当我阅读C ++ 11的设计目标时,它提到了零开销原则,而没有使用该原则的任何示例或功能。我可以理解,它可以避免降低现有代码的性能。但,
我正在准备一个sagemaker PIPE 模式数据集,以SageMaker使用PIPE模式训练时间序列模型。的PipeModeDataset是一个TensorFlow Dataset用于读SageMaker管道模式信道。我正在使用一个包含图像位置S3和每行标签的增强清单文件。我的模型接受批量图像 (512 x 512 x 1),每批次带有单个标签作为输入。我想到了使用窗口函数来捆绑从管道读取的图像。数据集生成请参考以下部分代码。
def _input_fn(channel):
"""Returns a Dataset for reading from a SageMaker PipeMode channel."""
features = {
'image-ref': tf.io.FixedLenFeature([], tf.string),
'label': tf.io.FixedLenFeature([3], tf.int64),
}
def parse(record):
parsed = tf.io.parse_single_example(record, features)
image = tf.io.decode_png(parsed['image-ref'], channels=1, dtype=tf.uint8)
image = tf.reshape(image, [512, 512, 1])
label = parsed['label']
return (image, label)
ds = PipeModeDataset(channel, record_format='TFRecord', benchmark=True, benchmark_records_interval=100)
ds = ds.map(parse)
print ("PipeModeDataset print0 …Run Code Online (Sandbox Code Playgroud) runtime-error tensorflow tensorflow-datasets amazon-sagemaker tensorflow2.0
我在为时间序列样本中的所有时间步长应用相同的 dropout 掩码时遇到了一个棘手的问题,以便 LSTM 层在一次前向传递中看到相同的输入。我阅读了多篇文章,但没有找到解决方案。以下实现是否支持这一点?或者这会在每个时间步随机丢弃不同的特征图?
dim = (420,48,48,1) # grayscale images of size 48x48
inputShape = (dim)
Input_words = Input(shape=inputShape, name='input_vid')
x = TimeDistributed(Conv2D(filters=50, kernel_size=(8,8), padding='same', activation='relu'))(Input_words)
x = TimeDistributed(MaxPooling2D(pool_size=(2,2)))(x)
x = TimeDistributed(SpatialDropout2D(0.2))(x)
x = TimeDistributed(BatchNormalization())(x)
x = TimeDistributed(Flatten())(x)
x = LSTM(200, dropout=0.2, recurrent_dropout=0.2)(x)
out = Dense(5,activation='softmax')(x)
model = Model(inputs=Input_words, outputs=[out])
opt = Adam(lr=1e-3, decay=1e-3 / 200)
model.compile(loss = 'categorical_crossentropy', optimizer=opt,metrics = ['accuracy'])
Run Code Online (Sandbox Code Playgroud)
如果不是,在 keras 上有什么好的解决方案?我可以使用带有噪声形状的 Dropout来解决我的问题吗?
我有一个LogDebug用于日志写入的可变函数.记录以两种模式进行.LogDebugEx在大多数情况下,我的应用程序将可变参数转发给另一个可变参数函数,因此该路径需要优化.具体来说vsnprintf,我对callgrind图上的一些请求需要38%.请注意,此功能可针对单个请求多次调用.
void LogDebug(const char* zFormat, ...)
{
char zDesc[5000];
va_list ap;
va_start(ap, zFormat);
vsnprintf(zDesc, 5000, zFormat, ap); // Need to optimize in remode mode.
va_end(ap);
if (m_logMode == LOG_MODE_LOCAL) // Does not need to optimize this mode.
{
// This mode is not interested.
}
else // m_logMode == LOG_MODE_REMOTE, critical path
{
LogDebugEx("%s", zDesc); // Forwarded to new variadic function
}
}
Run Code Online (Sandbox Code Playgroud)
问题:我需要避免zDesc在转发到LogDebugEx函数之前将整个参数列表复制到数组.有没有一种办法可以完全向前可变参数来LogDebug为 LogDebugEx功能?
如果不改变函数调用,任何其他奇特的方法也可以 …
c++ optimization variadic-functions perfect-forwarding c++11
我是React-native的新手我在尝试构建我的第一个应用程序时遵循了所有指令我遇到了这个错误.我有明确的捕获重启npm但仍然有这个错误.
The development server returned response error code: 500
URL: http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false
Body:
{"originModulePath":"F:\\React Native\\AttendenceSystem\\node_modules\\react-native\\Libraries\\react-native\\react-native-implementation.js","targetModuleName":"AccessibilityInfo","message":"Unable to resolve module `AccessibilityInfo` from `F:\\React Native\\AttendenceSystem\\node_modules\\react-native\\Libraries\\react-native\\react-native-implementation.js`: Module `AccessibilityInfo` does not exist in the Haste module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches: `watchman watch-del-all`.\n 2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n 3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`. 4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.","errors":[{"description":"Unable to resolve module …Run Code Online (Sandbox Code Playgroud) c++ ×3
c++11 ×3
optimization ×2
tensorflow ×2
android ×1
dropout ×1
keras ×1
lstm ×1
module ×1
react-native ×1