'Deeplearning4j example does not work with gradle

I am trying to run CnnSentenceClassification from deeplearning4j example. I moved this file to my Gradle project. When I run the class from the eclipse it works fine. However when I run it from ./gradlew run I get following error:

Exception in thread "main" java.lang.ExceptionInInitializerError
at 
main.CnnSentenceClassification.main(CnnSentenceClassification.java:75)
Caused by: java.lang.RuntimeException: 
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: 
Please ensure that you have an nd4j backend on your classpath. Please 
see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:6089)
at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:201)
... 1 more
Caused by: 
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: 
Please ensure that you have an nd4j backend on your classpath. Please 
see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:258)
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:6086)
... 2 more

I checked and nd4j-api-0.9.1.jar is in my classpath. This is my build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'

repositories {
    jcenter()
}

mainClassName="main.CnnSentenceClassification"

dependencies {
    compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '0.9.1'
    compile group: 'org.deeplearning4j', name: 'deeplearning4j-nlp', version: '0.9.1'       

    testCompile group: 'org.nd4j', name: 'nd4j-native-platform', version: '0.9.1'
    compile group: 'org.nd4j', name: 'nd4j-api', version: '0.9.1'

    compile "org.slf4j:slf4j-simple:1.7.25"
    compile "org.slf4j:slf4j-api:1.7.25"
}


Solution 1:[1]

I was having the same problem. You need an ND4J backend, which means updating your dependency tree.

For Maven builds, add the following dependency to your project's pom:

<dependency>
    <groupId>org.nd4j</groupId>
    <artifactId>nd4j-native</artifactId>
    <version>0.9.1</version>
</dependency>

For Gradle builds, just add the following line in your dependencies:

compile "org.nd4j:nd4j-native:0.9.1"

This native backend uses the CPU for computations. There is another dependency for a CUDA-enabled graphics card.

I found this link helpful: DL4J Performance Debugging

Solution 2:[2]

You don't mention if the staff table of up-loaded files is a different table then the one that supposed to drive the grid.

if it is for some reason, then build a group by query that does not include the file(s) column, and group by so you wind up with a SINGLE row for each staff member.

So, then we can drop in a grid list this:

And I am going to use a listbox in place of a combo (dropdown), so it will NICE display the files - you can change that to a dropdown if you want - same code

So, the markup might be this:

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataKeyNames="ID" CssClass="table table-hover" OnRowDataBound="GridView1_RowDataBound">
            <Columns>
                <asp:BoundField DataField="Firstname" HeaderText="First Name"  />
                <asp:BoundField DataField="LastName" HeaderText="Last Name"    />
                <asp:BoundField DataField="TrainingDate" HeaderText="Training Date"       DataFormatString="{0:yyyy-MM-dd}" />
                <asp:BoundField DataField="ApplicationDate" HeaderText="Application Date" DataFormatString="{0:yyyy-MM-dd}" />
                <asp:BoundField DataField="ProgramTitle" HeaderText="Program Title"  />
                <asp:BoundField DataField="TrainingCost" HeaderText="Training Cost"  DataFormatString="{0:c}" />

                <asp:TemplateField HeaderText="Documents Submitted">
                    <ItemTemplate>
                        <asp:ListBox ID="cboFiles" runat="server" Width="200PX"
                            DataTextField ="FileName"
                            DataValueField="FileName">                
                        </asp:ListBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Note how we added a listbox (as noted, use a drop down if you want).

So, the code to fill this gv would thus be this:

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            LoadGrid();
    }

    void LoadGrid()
    {
        GridView1.DataSource = MyRst("SELECT * from Users ORDER BY FirstName");
        GridView1.DataBind();
    }


    DataTable MyRst(string strSQL)
    {
        DataTable rstData = new DataTable();
        using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
        {
            using (SqlCommand cmdSQL = new SqlCommand(strSQL, conn))
            {
                conn.Open();
                rstData.Load(cmdSQL.ExecuteReader());
            }
        }

        return rstData;
    }

However, for each row, we need to load up the list of files for that one row. As noted, I don't know if you have two tables here - or one. (but, it really does not matter - as noted, use a group-by for this main grid data source.

Now, the only extra part is to use the gv "row data bound" event. This fires for each row during render, and is the idea event to load up the combo or list box.

That code is thus this:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // get PK row id (user id)
            int? PKID = GridView1.DataKeys[e.Row.RowIndex]["ID"] as int?;
            string strSQL = "SELECT FileName FROM MyFiles WHERE User_ID = " + PKID;
            DataTable rstFiles = MyRst(strSQL);
           ListBox cboFiles = e.Row.FindControl("cboFiles") as ListBox;

            cboFiles.DataSource = rstFiles;
            cboFiles.DataBind();
            cboFiles.Rows = 1;
            if (rstFiles.Rows.Count > 1)
                cboFiles.Rows = rstFiles.Rows.Count;
        }
    }

And above I do have two columns. One is JUST file name, and one column is the full path name + file to the up-load folder. If you don't have just a file name column, then we can write a bit of code to JUST include + show file name.

the results of running the above is thus this:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2