Error in keras_model_sequential() : file name conversion problem -- name too long?

Hi,I am using Rstudio in Windows 10. When I use keras package,it print out this error .
model<-keras_model_sequential()
Error: file name conversion problem -- name too long?
why?And how to fix it?

Can you please provide a minimal reprex (reproducible example)? The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it: please help me help you!

If you've never heard of a reprex before, start by reading "What is a reprex", and follow the advice further down that page.

1 Like

Like this?

Merry Christmas! And no, not like that :wink: please read the link that Max kindly posted, or this one:

Again, Merry Christmas! :gift::christmas_tree: Or Happy Holidays, if you prefer. Best of luck with keras!

# 加载包与数据读取
library(keras)  #加载keras包,高度模块化的神经网络包
library(dplyr) #加载dplyr包,处理结构化数据
#> 
#> 载入程辑包:'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(ggthemes) #ggthemes是ggplot2的主题拓展包
library(lubridate) #处理时间数据
#> 
#> 载入程辑包:'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date
library(Sequential) #完成多个网络层的线性堆叠
set.seed(7)#设置随机数
setwd("E:\\数据挖掘")
dataframe<-read.csv("text2.csv")

#构建LSTM模型
open<-function(){
  model<-keras_model_sequential() %>%
    layer_lstm(units = 4,input_shape = c(1, look_back)) %>%#引入LSTM层
    layer_dense(units = 1) %>%  #引入dense层
    
    
    compile(loss = 'mean_squared_error',optimizer = 'adam') %>%#设置损失函数和优化器
    fit(train$dataX,
        train$dataY,
        epochs = 100,
        batch_size = 2,
        verbose = 2) #设置各项参数
  
}
model<-open()
#> Error: 转换文件名时出了问题--名字太长了?

Created on 2018-12-25 by the reprex package (v0.2.1)

This one must be right.Merry Christmast!:christmas_tree::confetti_ball:

:clap::clap::clap: it's nearly perfect! The only problem is that I can't reproduce your issue without the text2.csv file. If you can put it somewhere in a shared location on the Internet (Dropbox, Google Drive, a GitHub gist or any of the various data sharing sites), then I'll be able to help :slight_smile:

1 Like

Ok,I just put my data to guithub gist.You can search zalzi/gist.The fist one is the text2.csv.(https://github.com/zalzi/gist)
Thank you for your help.:blush:

1 Like

Perfect! I'm happily busy entertaining my six nephews these days :relaxed: but I'll have a look at your issue in the needs days

我也遇到了同样的问题,想问一下 你解决了没有

Ouch! I forgot about this. I’ll have a look next year :slight_smile:

Hi, @zizi,

I finally managed to find the time to reply to you :slight_smile: I ran your code here:

https://rstudio.cloud/project/162323

I get the error

Error in normalize_shape(input_shape) : object 'look_back' not found

but this is clearly due to the fact that you don't define lookback (used here)

layer_lstm(units = 4,input_shape = c(1, look_back)) %>%#引入LSTM层

anywhere in your code. Can you fix that? Also, can you please rewrite the comments in English (I think they're Standard Chinese now)? That would make it easier for me to follow the code. I think I understand what you're trying to do here (you want to predict output y(t) based on preceding inputs y(t-1), y(t-2), ..., y(t-k) where look_back <- k), but I'd rather be sure than having to guess.

Also, even if I substitute look_back with, say, 4, your code keeps failing because you didn't define your training set anywhere. Please include the training set bit and try again :wink: Also, as a general rule, I'd never train a NN without at the same time validating it on a validation set, but I digress.

EDIT never mind about translating the comments to English. In the end I was able to read all of them :slight_smile: it looks like you work on a drive called "Data Mining"...:wink:

Please, in the future enclose your code between backticks like this (I have already done it for you in the previous post).

```
Code
```

This makes your code much easier to read.

No problem for what it concerns the comments, but the code doesn't run, because there are a lot of weird characters (maybe due to copying & pasting from somewhere?). Let's wait until after your exam, when you'll have time to format your code properly.

PS if this is a homework question, please state it clearly and be sure to follow our homework policy:

My question is not related to homework.I just want know why I can't run the code "model<- keras_model_sequential()" to build a LSTM model.But I can run the same code in other's computer.Is it sonmething wrong with my computer?

Ah, knowing that your code runs on someone's else computer, but not on yours, makes a big difference. I have no idea if there's something wrong with your computer, since I don't have access to it. But maybe there's simply something wrong with your installation of keras. After installing keras, did you run these two lines of code in the R console?

library(keras)
install_keras()

Of course.When I run the code "install_keras()" ,it print out same error ."Error in dir.exists(x) : file name conversion problem -- name too long?"

Ah! If you had told me before, I wouldn't have insisted for a reprex of your full LSTM training code :wink: It looks like there's something wrong, maybe in your keras installation, or possibly with your R installation/system configuration. Try uninstalling and reinstalling keras & tensorflow:

remove.packages("keras")
remove.packages("tensorflow")

Restart R, and do:

install.packages("keras")
library(keras)
install_keras()

If this doesn't solve your issue, I cannot help you further since I'm not familiar with the innards of the keras package. I suggest you ask a new question, explaining very clearly that your error is not related to a specific keras scripts, but it happens even if you just run the simple command

install_keras()

HTH

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.