Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 加速器数据对于模型预测应该具有什么结构?_Python_Android_Tensorflow_Keras_Tensorflow Lite - Fatal编程技术网

Python 加速器数据对于模型预测应该具有什么结构?

Python 加速器数据对于模型预测应该具有什么结构?,python,android,tensorflow,keras,tensorflow-lite,Python,Android,Tensorflow,Keras,Tensorflow Lite,我创建了Keras模型,将其转换为TensorFlow,然后将其转换为TensorFlow lite。我想用我的TFLite模型,通过手机上的加速器信号来预测人类活动。这是我的模型的顺序: N_FEATURES = 3 PERIOD = 80 model = Sequential() model.add(Reshape((const.PERIOD, const.N_FEATURES), input_shape=(const.PERIOD * const.N_FEATURES,))) mode

我创建了Keras模型,将其转换为TensorFlow,然后将其转换为TensorFlow lite。我想用我的TFLite模型,通过手机上的加速器信号来预测人类活动。这是我的模型的顺序:

N_FEATURES = 3
PERIOD = 80


model = Sequential()
model.add(Reshape((const.PERIOD, const.N_FEATURES), input_shape=(const.PERIOD * const.N_FEATURES,)))
model.add(Conv1D(100, 10, activation='relu', input_shape=(const.PERIOD, const.N_FEATURES)))
model.add(Conv1D(100, 10, activation='relu'))
model.add(MaxPooling1D(const.N_FEATURES))
model.add(Conv1D(160, 10, activation='relu'))
model.add(Conv1D(160, 10, activation='relu'))
model.add(Flatten())
model.add(Dropout(0.2))
model.add(Dense(7, activation='softmax'))
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])


x_test.shape = (12369, 240)
y_test.shape = (12369, 7)
x_train.shape = (49476, 240)
y_train.shape = (49476, 7)
我想问一下我需要在Android应用程序中传递给模型以预测活动的数据形状。我使用的函数是
解释器。我需要使用一个包含三个列表的数组?它们中的每一个都有来自加速器(x、y和z)的一个轴的数据,或者我需要创建其他东西

这是我的第一个模型,所以欢迎任何其他提示

编辑:

List samples=collector.getSamples();
float[][]floatInputBuffer=新的float[200][3];
对于(int i=0;i<200;i++){
floatInputBuffer[i][0]=samples.get(i).getX();
floatInputBuffer[i][1]=samples.get(i).getY();
floatInputBuffer[i][2]=samples.get(i).getZ();
}
对象[]inputArray={floatInputBuffer,新int[]{5000}};
Map outputMap=newhashmap();
outputMap.put(0,新浮点[1][labels.size()]);
解释器interpeter=null;
试一试{
interpeter=新的解释器(loadModel(getAssets(),MODEL_PATH.split)(“file:///android_asset/", -1)[1]));
}捕获(IOE异常){
e、 printStackTrace();
}
interpeter.runForMultipleInputsOutputs(inputArray,outputMap);

您需要一个形状为
的数组(示例、时间帧、尺寸x\u y\u z)

它已经在您的模型中使用
input\u shape=(const.PERIOD,const.N\u特性)
进行了很好的定义


因此,
(示例,const.PERIOD,const.N_特性)
是您的数据格式

您需要一个形状为
的数组(示例、时间帧、维度x y z)

它已经在您的模型中使用
input\u shape=(const.PERIOD,const.N\u特性)
进行了很好的定义


因此,
(示例,const.PERIOD,const.N_特性)
是您的数据格式

无论训练模型时使用何种输入大小,在使用解释器执行推理时,都必须发送相同大小的输入(批量大小除外)。如果您在解释器上使用
run
方法,那么您可能只传递了一个输入,但是由于您使用的是
runForMultipleInputsOutputs
,因此您可以将数据批处理在一起,然后发送它


因此,您的模型的输入形状为
(const.PERIOD*const.N\u FEATURES)
。我相信这个产品是240。因此,对TFLite模型的输入必须是
(,240)

无论在训练模型时使用何种输入大小,在使用解释器执行推理时,都必须发送相同大小的输入(批量大小除外)。如果您在解释器上使用
run
方法,那么您可能只传递了一个输入,但是由于您使用的是
runForMultipleInputsOutputs
,因此您可以将数据批处理在一起,然后发送它


因此,您的模型的输入形状为
(const.PERIOD*const.N\u FEATURES)
。我相信这个产品是240。因此,您对TFLite模型的输入必须是
(,240)

“如果您在解释器上使用run方法,那么您可能只传递了一个输入”-这可能会更容易,我想我需要使用
runformMultipleInputSoutputs
方法。如果我使用
run
方法,那么我需要发送一个向量,该向量在给定时刻包含来自加速度计的一个样本,每个坐标线包含一个值?“如果您在解释器上使用run方法,那么您可能只传递了一个输入”-这可能会更容易,我想我需要使用
runForMultipleInputsOutputs
方法。如果我使用
run
方法,那么我需要发送一个向量,其中包含给定时刻加速度计的一个样本,每个坐标线包含一个值?我编辑了我的问题并添加了一些代码。我收到java.lang.IllegalArgumentException:runForMultipleInputsOutputs上的无效输入张量索引:1。我做错了什么?我编辑了我的问题并添加了一些代码。我收到java.lang.IllegalArgumentException:runForMultipleInputsOutputs上的无效输入张量索引:1。我做错了什么??
        List<Sample> samples = collector.getSamples();
        float[][] floatInputBuffer = new float[200][3];

        for(int i = 0; i < 200; i++) {
            floatInputBuffer[i][0] = samples.get(i).getX();
            floatInputBuffer[i][1] = samples.get(i).getY();
            floatInputBuffer[i][2] = samples.get(i).getZ();
        }

        Object[] inputArray = {floatInputBuffer, new int[]{5000}};
        Map<Integer, Object> outputMap = new HashMap<>();
        outputMap.put(0, new float[1][labels.size()]);
        Interpreter interpeter = null;
        try {
            interpeter = new Interpreter(loadModel(getAssets(), MODEL_PATH.split("file:///android_asset/", -1)[1]));
        } catch (IOException e) {
            e.printStackTrace();
        }

        interpeter.runForMultipleInputsOutputs(inputArray, outputMap);