RuntimeError:仅将元组,列表和变量支持为JIT输入,但得到NoneType

时间:2019-03-10 08:00:17

标签: pytorch onnx

我的代码是

a=torch.randn(1,80,100,requires_grad=True)
torch.onnx.export(waveglow,a, "waveglow.onnx")

我正在尝试将PyTorch模型导出为ONNX格式,以便可以在TensorRT中使用它。在PyTorch中测试模型时,输入张量尺寸为(1,80,x),其中x根据输入文本长度而变化(我使用的模型是名为waveglow的TTS模型)

当我尝试运行以上代码以将模型导出到onnx时,我总是会收到此错误

RuntimeError: Only tuples, lists and Variables supported as JIT inputs, but got NoneType

请帮助

1 个答案:

答案 0 :(得分:2)

鉴于您具有NoneType,也许您可​​以检查是否存在实际输入,因为事实是,您实际上得到了<?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.Insets?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <VBox alignment="TOP_CENTER" spacing="10.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="UI.BaseApps.Calculator.MainController"> <padding> <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/> </padding> <children> <TextField fx:id="txtDisplay" disable="true" alignment="CENTER_RIGHT" editable="false" minHeight="-Infinity" prefHeight="50.0" text="0"/> <GridPane hgap="10.0" vgap="10.0" VBox.vgrow="ALWAYS"> <columnConstraints> <ColumnConstraints hgrow="SOMETIMES" minWidth="-Infinity"/> <ColumnConstraints hgrow="SOMETIMES" minWidth="-Infinity"/> <ColumnConstraints hgrow="SOMETIMES" minWidth="-Infinity"/> <ColumnConstraints hgrow="NEVER" minWidth="-Infinity"/> <ColumnConstraints hgrow="SOMETIMES" minWidth="-Infinity"/> <ColumnConstraints hgrow="SOMETIMES" minWidth="-Infinity"/> </columnConstraints> <rowConstraints> <RowConstraints minHeight="-Infinity" vgrow="SOMETIMES"/> <RowConstraints minHeight="-Infinity" vgrow="SOMETIMES"/> <RowConstraints minHeight="-Infinity" vgrow="SOMETIMES"/> <RowConstraints minHeight="-Infinity" vgrow="SOMETIMES"/> </rowConstraints> <children> <Button fx:id="btn7" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="7"/> <Button fx:id="btn8" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="8" GridPane.columnIndex="1"/> <Button fx:id="btn9" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="9" GridPane.columnIndex="2"/> <Separator orientation="VERTICAL" prefHeight="200.0" GridPane.columnIndex="3" GridPane.rowSpan="4"/> <Button fx:id="btnDivide" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="÷" GridPane.columnIndex="4"/> <Button fx:id="btnClear" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="C" GridPane.columnIndex="5"/> <Button fx:id="btn4" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="4" GridPane.rowIndex="1"/> <Button fx:id="btn5" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="5" GridPane.columnIndex="1" GridPane.rowIndex="1"/> <Button fx:id="btn6" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="6" GridPane.columnIndex="2" GridPane.rowIndex="1"/> <Button fx:id="btnMultiply" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="x" GridPane.columnIndex="4" GridPane.rowIndex="1"/> <Button fx:id="btn1" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="1" GridPane.rowIndex="2"/> <Button fx:id="btn2" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="2" GridPane.columnIndex="1" GridPane.rowIndex="2"/> <Button fx:id="btn3" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="3" GridPane.columnIndex="2" GridPane.rowIndex="2"/> <Button fx:id="btn0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="0" GridPane.columnSpan="2" GridPane.rowIndex="3"/> <Button fx:id="btnDecimal" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="." GridPane.columnIndex="2" GridPane.rowIndex="3"/> <Button fx:id="btnSubtract" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="-" GridPane.columnIndex="4" GridPane.rowIndex="2"/> <Button fx:id="btnAdd" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="+" GridPane.columnIndex="4" GridPane.rowIndex="3"/> <Button fx:id="btnEquals" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="=" GridPane.columnIndex="5" GridPane.rowIndex="2" GridPane.rowSpan="2"/> <Button fx:id="btnBackspace" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="50.0" prefWidth="50.0" text="←" GridPane.columnIndex="5" GridPane.rowIndex="1"/> </children> </GridPane> </children> </VBox>

还有,什么理由不使用Variable?变量将您的输入转换为张量,该张量可以作为import javafx.application.Platform; import javafx.css.PseudoClass; import javafx.fxml.FXML; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; public class MainController { // Here we'll define our PseudoClass needed to set the style for each pressed Button private static final PseudoClass PRESSED = PseudoClass.getPseudoClass("pressed"); // Define FXML controls @FXML private TextField txtDisplay; @FXML private Button btn7, btn8, btn9; @FXML private Button btn4, btn5, btn6; @FXML private Button btn1, btn2, btn3; @FXML private Button btn0, btnDecimal; @FXML private Button btnMultiply, btnSubtract, btnAdd, btnDivide; @FXML private Button btnClear, btnEquals, btnBackspace; @FXML private void initialize() { // We need access to the Scene to register our key listeners, so we need to wrap the code in a Platform.runLater(). If we try to do this without Platform.runLater(), we'll get a NullPointerException because txtDisplay hasn't been rendered yet. Platform.runLater(() -> { Scene scene = txtDisplay.getScene(); // Add a listener to capture any key that is pressed. We add this to the entire scene and we can then change the style of the corresponding button accordingly. scene.setOnKeyPressed(event -> { // We need to know which Button we're working with Button button = getButton(event.getCode()); // Add our "pressed" style to the Button if (button != null) button.pseudoClassStateChanged(PRESSED, true); }); // Once the user releases the key, remove our custom style and trigger whatever onAction() code has been applied to the corresponding Button. scene.setOnKeyReleased(event -> { Button button = getButton(event.getCode()); if (button != null) { button.pseudoClassStateChanged(PRESSED, false); // Fire the button's onAction() button.fire(); } }); }); } // Helper method to get the Button that corresponds to the pressed key. The Scene.setOnKeyPressed() listener provides the KeyCode for the pressed key. We can use that to determine which of our Buttons to trigger. private Button getButton(KeyCode keyCode) { switch (keyCode) { case NUMPAD0: return btn0; case NUMPAD1: return btn1; case NUMPAD2: return btn2; case NUMPAD3: return btn3; case NUMPAD4: return btn4; case NUMPAD5: return btn5; case NUMPAD6: return btn6; case NUMPAD7: return btn7; case NUMPAD8: return btn8; case NUMPAD9: return btn9; case DECIMAL: return btnDecimal; case DIVIDE: return btnDivide; case ADD: return btnAdd; case MULTIPLY: return btnMultiply; case SUBTRACT: return btnSubtract; case ENTER: return btnEquals; case BACK_SPACE: return btnBackspace; case ESCAPE: return btnClear; } return null; } } 的输入。