torch.jit.trace doesn’t record data flowing over Python values, they instead just get recorded as constants with respect to the inputs provided to torch.jit.trace. So it looks like for your model the batch size is being recorded into the graph and will be fixed so no other batch sizes work:
Consider a batch size of 10 and the resulting graph
trace_net = torch.jit.trace(model, [torch.ones(10, 1, 15, 512)])
  _30 = torch.copy_(_29, torch.view(_27, [10, 4]), False)                                                                                                                                                                          

versus a batch size of 3
trace_net = torch.jit.trace(model, [torch.ones(3, 1, 15, 512)])
  _30 = torch.copy_(_29, torch.view(_27, [3, 4]), False)                                                                                            

The only way around this is to use torch.jit.script instead of torch.jit.trace which will compile your code instead of tracing its execution. For example
        ...
        out = F.relu(self.bn(out))
        out = out.permute(0, 3, 2, 1)
        out_final = torch.zeros([out.size()[0], self.num_out, self.num_categories])
        i = 0
        # ModuleLists cannot be indexed in TorchScript, so the loop here must
        # be changed
        for fc in self.fc:
            x1 = fc(out[:, :, i, :])
            out_final[:, i, :] = x1[:, 0, :]
            i += 1

        out_final = self.m(out_final)
        return out_final


model = Model_W512H15(kernelSize=(7, 9))
model.eval()
trace_net = torch.jit.script(model)